问题描述
我有带有不同片段的“ 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);
解决方法
您需要调用以下方法清除所有后退堆栈
finishAffinity();