Search code examples
androidandroid-activity

How To Clear Activity Stack Below An Activity


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.


Solution

  • 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.