如何以挂起的意图启动Activity并清除所有Backstack?

时间:2020-10-22 18:49:30

标签: android android-intent notifications android-notifications android-pendingintent

我有带有不同片段的“ HomeActivity”。我想在我单击未决Intent(HomeActivity)时清除HomeActivity中的所有Backstack。如果有其他片段打开,请单击“ pending”,将其清除。

Andoidmanifest.XML

<activity
        android:screenOrientation="portrait"
        android:launchMode = "singleTask"
        android:taskAffinity=""
        android:excludeFromRecents="true"
        android:name=".HomeActivity"
        android:label="@string/title_activity_home"
        android:theme="@style/AppTheme.NoActionBar" />

通知意图代码如下:

 Intent notifyIntent = new Intent(this, SplashScreen.class);   //SplashScreen is first activity
                // Set the Activity to start in a new, empty task
                notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                        | Intent.FLAG_ACTIVITY_CLEAR_TASK);

PendingIntent pendingIntent = PendingIntent.getActivity(context, id, notifyIntent , PendingIntent.FLAG_UPDATE_CURRENT);

                Common.showNotification(this, new Random().nextInt(),
                        dataRecv.get(Common.NOTI_TITLE),
                        dataRecv.get(Common.NOTI_CONTENT),
                        pendingIntent);

1 个答案:

答案 0 :(得分:0)

您需要调用以下方法清除所有后退堆栈

finishAffinity();