Android 从通知部分标记\u活动\u清除\u顶部不工作
我有一个简单的用例。我的活动如下所示:Android 从通知部分标记\u活动\u清除\u顶部不工作,android,android-intent,android-activity,android-notifications,android-notification-bar,Android,Android Intent,Android Activity,Android Notifications,Android Notification Bar,我有一个简单的用例。我的活动如下所示: A>B>C 现在,我收到推送通知 我在我的gcminentservice课程中执行以下操作: 在onMessage中 Intent notificationIntent = new Intent(context, A.class); PendingIntent contentIntent = PendingIntent.getActivity(context,0, notificationIntent, PendingIntent
A>B>C
现在,我收到推送通知
我在我的gcminentservice
课程中执行以下操作:
在onMessage
中
Intent notificationIntent = new Intent(context, A.class);
PendingIntent contentIntent =
PendingIntent.getActivity(context,0, notificationIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
notification.setContentIntent(contentIntent);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP );
我的期望是活动B,C
应该从活动堆栈中删除,并且您应该被重新定向到活动A
然而,正在发生的是,A
被打开;但当你们按下“后退”按钮时,我会再次按顺序得到C,B,A
我做错了什么
以下是我尝试过的东西:
我已经试过了
notificationIntent.setFlags(Intent.FLAG\u ACTIVITY\u REORDER\u TO\u FRONT)代码>,,
notificationIntent.setFlags(Intent.FLAG\u ACTIVITY\u CLEAR\u TOP,Intent.FLAG\u ACTIVITY\u SINGLE\u TOP)代码>
我保留了对上一个前台活动的静态引用,并将其作为context
传递
似乎什么都不管用。试试这个。这可能对你有帮助。一旦你测试过,请告诉我
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(notificationIntent);
试试这个。这可能对你有帮助。一旦你测试过,请告诉我
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(notificationIntent);
试试这个
Intent notificationIntent = new Intent(context, YourActivity.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;
// Vibrate if vibrate is enabled
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);
试试这个
Intent notificationIntent = new Intent(context, YourActivity.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;
// Vibrate if vibrate is enabled
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);
将活动的启动模式设置为“singleTask”:
将活动的启动模式设置为“singleTask”:
谢谢您的帮助,但您提供的解决方案无效。导致了同样的行为@ranjjose您可以尝试使用这些标志,但在创建pendingent
之前,请将它们添加到notificationIntent
,谢谢@LordRaydenMK。命令也是一个问题。事实上,我添加了notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK)代码>由@Arun Antoney建议,然后根据@LordRaydenMK建议更改顺序。成功了!谢谢大家。谢谢你的帮助,但是你提供的解决方案不起作用。导致了同样的行为@ranjjose您可以尝试使用这些标志,但在创建pendingent
之前,请将它们添加到notificationIntent
,谢谢@LordRaydenMK。命令也是一个问题。事实上,我添加了notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK)代码>由@Arun Antoney建议,然后根据@LordRaydenMK建议更改顺序。成功了!谢谢大家;但正如我在“我已经尝试过的事情”一节中提到的,我尝试了“notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);”。此外,我还开发了针对同一博客的推送通知。:)我们都在使用相同的方法,请在你的应用程序中再次测试;但正如我在“我已经尝试过的事情”一节中提到的,我尝试了“notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);”。此外,我还开发了针对同一博客的推送通知。:)我们都使用相同的方法,请在你的应用程序中再次测试。嗨,你能分享你的电子邮件id吗?@ArunAntoney:ranjjose@gmail.comHi你能分享你的电子邮件id吗?@ArunAntoney:ranjjose@gmail.com