Android - 如何打开推送通知深层链接意图,关闭时返回主屏幕? [英] Android - how to open a push notification deep-link intent that, when closed, returns to the Home screen?

查看:40
本文介绍了Android - 如何打开推送通知深层链接意图,关闭时返回主屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个接收器来接收和显示推送通知 - 当用户按下推送通知时,它会在我的应用程序中打开一个深层链接.问题是,当用户按下返回"时,他不会返回到主屏幕,而是会转到我的应用程序之前在应用程序后台打开的任何屏幕 - 即使应用程序在他按下之前被最小化通知.

I've created a receiver to receive and display push notifications - when the user presses on the push notification it opens a deep-link within my application. The problem is that when the user presses "back" he doesn't exit back to the home screen, but rather he goes to whatever screens for my application were open before on the application backstack - even if the application was minimized before he pressed on the notification.

我需要的行为是让用户在主屏幕上,让他打开通知面板,按下我的通知,进入我的应用程序中的深层链接页面,当他按下后退按钮时 -我希望他再次完全退出到主屏幕.我不希望他以任何方式与主应用程序的后台堆栈进行交互.

The behavior that I need is for the user to be on the home screen, for him to open the notifications panel, press on my notification, go into the deep link page in my app, and when he presses the back button - I want him to exit all the way out to the home screen again. I don't want him in any way interacting with the backstack for the main application.

我已经为推送通知中的 pendingIntent 尝试了多种标志组合.从 FLAG_ACTIVITY_TASK_ON_HOME 到 FLAG_ACTIVITY_NEW_TASK 到 FLAG_ACTIVITY_SINGLE_TOP 等的所有内容.似乎没有任何组合可以满足我的需求 - 在每种情况下,打开应用程序最小化的深层链接总是会在我按下时返回应用程序历史记录中的下一页后退按钮.我该如何解决这个问题?

I've tried numerous combinations of flags for the pendingIntent in the push notification. Everything from FLAG_ACTIVITY_TASK_ON_HOME to FLAG_ACTIVITY_NEW_TASK to FLAG_ACTIVITY_SINGLE_TOP, etc. No combination seems to give me what I want - in every single case, opening the deep link with the app minimized will always return me to the next page in the history of the app when I press the back button. How can I solve this?

示例代码:

        Intent notificationIntent = new Intent(this, DeepLink.class);
    notificationIntent.setData(Uri.parse(url));
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 1,       notificationIntent, 0);

推荐答案

已解决.深层链接类开始为每个深层链接创建一个意图,这些要求我为每个深层链接设置标志 NEW_TASK 和 CLEAR_TASK.在那之后 - 一切正常.

Solved. The deeplink class was starting an intent for each deeplink and these required that I set the flags NEW_TASK and CLEAR_TASK for each one. After that - everything worked.

这篇关于Android - 如何打开推送通知深层链接意图,关闭时返回主屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆