简体   繁体   中英

Clearing the Launcher Activity from the stack

In my app, I have activity A (Launcher/Main Activity) ,B,C. A launches B or C depending on if the user is authenticated.

Now how do I remove A such that when the back button is pressed it just exits the app, not to A. Setting the flag FLAG_ACTIVITY_CLEAR_TOP doesn't seem to work.

@Override
public void onBackPressed{
    super.onBackPressed();
    finish(); // finish activity B or C

    //also finish activity A
}

I think you need to set

android:noHistory="true"

on A. You might also need to launch B/C with these Flags:

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);    

Finally, you can finish all activities under the current one in the task stack with the same affinity by calling:

finishAffinity()

For further information: Android: Clear the back stack

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM