我有一个简单的用例。我的 Activity 如下所示:
A > B > C
现在,我收到一条推送通知。
我在我的 GCMintentService
类中执行以下操作:
在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 );
我的期望是, Activity B、C
应从 Activity 堆栈
中删除,并且您应重定向到 Activity A
。
然而,发生的情况是,A
被打开;但是当你点击后退按钮时,我会再次按顺序得到 C、B、A
!!
我做错了什么?
这是我尝试过的事情:
我已经尝试过
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
,notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP, Intent.FLAG_ACTIVITY_SINGLE_TOP);
我保留了对最后一个前台 Activity 的静态引用,并将其作为
上下文
传递。
似乎没有什么作用。
最佳答案
试试这个。它可能对你有帮助。测试后请告诉我。
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(notificationIntent);
关于android - FLAG_ACTIVITY_CLEAR_TOP 在通知部分不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24652928/