Android 当从状态栏单击通知项时,如何清除后台堆栈活动?
我正在做一个聊天项目。当收到来自GCM的推送通知时,我需要导航到聊天联系人列表并清除以前打开的我的应用程序活动。我建议您阅读有关的文档,在GCMinent服务中传递挂起的意图时,有必要设置意图标志。 代码如下。如果有人在这个概念上挣扎,请使用它Android 当从状态栏单击通知项时,如何清除后台堆栈活动?,android,back-stack,Android,Back Stack,我正在做一个聊天项目。当收到来自GCM的推送通知时,我需要导航到聊天联系人列表并清除以前打开的我的应用程序活动。我建议您阅读有关的文档,在GCMinent服务中传递挂起的意图时,有必要设置意图标志。 代码如下。如果有人在这个概念上挣扎,请使用它 PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class).setFlags(Intent.F
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TASK), 0);
按照saranya的建议,在清单中的活动标记中添加“taskAffinity”和“excludeFromRecents”以及“flag_activity_NEW_TASK”标志,这对我来说是个好办法
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
android:taskAffinity=""
android:excludeFromRecents="true">
val notificationIntent = Intent(this,
MainActivity::class.java).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or
Intent.FLAG_ACTIVITY_CLEAR_TASK)
val pendingIntent: PendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0)
val notificationIntent=意图(此,
MainActivity::class.java).setFlags(Intent.FLAG\u ACTIVITY\u NEW\u任务或
意图。标记(活动清除任务)
val pendingent:pendingent=pendingent.getActivity(this,0,notificationIntent,0)