Search code examples
androidandroid-activity

Android Popping off the Activity Stack


In our app, we have Activities A,B,C,D, and E. The user usually goes from A to E, moving through B,C,D.

In Activity E we want to go back to A, and get rid of B,C,D from the stack. We don't want to recreate A from E.

How do I 'pop off' B,C,D from the stack and then return to A?


Solution

  • If A is already running, you can use the FLAG_ACTIVITY_CLEAR_TOP flag when starting an intent to go back to A.

    See also, similar questions:

    How to clear current activities in the stack?

    how to kill sub activities and bring activity to top of stack