我目前在通知栏中显示一条通知,当用户单击它时,它应该将它们带到我的应用程序的根Activity。Android - 通知PendingIntent进入错误活动?
我用的android:finishOnTaskLaunch =“真” &机器人:clearTaskOnLaunch在我的清单=“真”来实现这个当用户按下从应用程序屏幕或主屏幕的应用程序图标。用户总是按照预期采取根本活动。
但是,当我从我的通知中使用以下代码时,用户将转到他们所在的最后一个屏幕,而不是StartActivity的根活动。
有谁知道我在做什么错?
Intent notificationIntent = new Intent(this, StartActivity.class);
contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(getApplicationContext(), getString(R.string.notification_app_name), notificationText, contentIntent);
mNotificationManager.notify(1, notification);
添加这些标志有助于但它仍然没有在重新启动后的工作:
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
当我重新启动我的应用程序设置服务运行的弹出通知,当我做到这一点,通知会恢复到旧的不需要的行为。
解决:
加入这个标志我通知的contentIntent解决问题 - Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED。
下面是一些优秀的信息在区域的链接Google dev group
能不能介绍一下你是如何使用的详细说明:FLAG_ACTIVITY_RESET_TASK_IF_NEEDED。 –