in my application, when I start a specific activity I want all the activities in the same package to be cleared from the stack underneath. Could someone help me on how to do this?
Also I do not want to use android:noHistory="true"
in the manifest because I only want the stack history to be cleared on starting this specific activity.
EDIT:
To make my point more clear, suppose I have activity a. From a I start activity b. From b I start c. But when I start c I want to clear b and a.
A task is a collection of activities that users interact with when trying to do something in your app. These activities are arranged in a stack—the back stack—in the order in which each activity is opened. For example, an email app might have one activity to show a list of new messages.
Oh guys, I figured out that you just have to put the following code with the Intent which starts the stack clearing activity:
Intent i = new Intent(this,MyActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
Thanks for your help though.
Try this,
Add android:launchMode="singleTop"
to the your Specific Activity that wanted to clear all the stacked activity.
Then use intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
and intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
when starting your Specific Activity.
Source: Android: Clear the back stack
Intent intent = new Intent(getApplicationContext(), YOUR_CLASS.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Set flag before the activity is started...whats the point of setting the flag after starting the activity....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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With