How to clear activity stacks below action

in my application, when I run a specific action, I want all the actions in one package to be removed from the stack under it. Can someone help me on how to do this? Also, I don't want to use android:noHistory="true" in the manifest, because I want the stack history to be cleared when this particular operation is run.

EDIT:

To make my point clearer, suppose I have activity a. From the start of work b. From b, we start c. But when I start c, I want to clear b and a.

+6
source share
4 answers

Oh guys, I realized that you just need to enter the following code with Intent, which starts the stack cleanup operation:

 Intent i = new Intent(this,MyActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(i); 

Thank you for your help.

+4
source

Try it,

Add android:launchMode="singleTop" to your specific activity that wants to clear all complex activity.

Then use intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) and intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) when starting your specific operation.

Source: Android: clear back stack

+1
source
 Intent intent = new Intent(getApplicationContext(), YOUR_CLASS.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); 
+1
source

Set the flag before the action starts ... what's the point of setting the flag after the activity starts ... the code should look something like this:

 Intent intent = new Intent(getContext(), ClassName.class); intent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP ); v.getRootView().getContext().startActivity(intent); removeSessionFiles(); 
+1
source

All Articles