How to add current activity to Activity Stack
Can anyone tell me if there is any way to add current activity to Activity Stack (Activities history). I have situation开发者_Python百科 as following:
- user starts new activity - A (which I don't want to put on stack)
- user starts new activity (B) from A
- user presses BACK button from B
- B is gone, but A is gone also
When user starts activity B, I want to keep A in history to be able to move back with BACK button.
The only thing I have in my mind is to starts new activity A from B in onKeyDown() method. But maybe is there a better way?
If you don't call finish() for activity A when user starts activity B it will be there when user finishes activity B.
That's actually what happens in the normal lifecycle of an application. If you don't call finish()
in A, the application will return to A when B finishes.
set android:clearTaskOnLaunch="true" in your root activity (in the manifest file)
also, unless you want to prevent going from B to A (when the user press back), you should drop the "no history" flag
docs:
If this attribute is set to "true" in the root activity of a task, the stack is cleared down to the root activity whenever the user leaves the task and returns to it. In other words, it's the polar opposite of alwaysRetainTaskState. The user always returns to the task in its initial state, even after a momentary absence
http://developer.android.com/guide/topics/fundamentals.html#clearstack http://developer.android.com/guide/topics/manifest/activity-element.html#clear
精彩评论