Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 453
Ian Vink Avatar asked Aug 18 '10 22:08

Ian Vink


People also ask

How do I get my activity back on Android?

Android activities are stored in the activity stack. Going back to a previous activity could mean two things. You opened the new activity from another activity with startActivityForResult. In that case you can just call the finishActivity() function from your code and it'll take you back to the previous activity.

What is activity stack?

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.

Does finish remove activity from stack?

The back button (by default) then 'pops' the stack, calling finish() on the topmost activity, destroying it and removing it from the back stack and taking you back to the previous activity.


2 Answers

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

like image 168
Cheryl Simon Avatar answered Sep 18 '22 12:09

Cheryl Simon


Use the android:noHistory property in the manifest:

http://developer.android.com/guide/topics/manifest/activity-element.html

like image 22
fredley Avatar answered Sep 17 '22 12:09

fredley