开发者

How to add current activity to Activity Stack

开发者 https://www.devze.com 2023-01-31 05:36 出处:网络
Can anyone tell me if there is any way to add current activity to Activity Stack (Activities history). I have situation开发者_Python百科 as following:

Can anyone tell me if there is any way to add current activity to Activity Stack (Activities history). I have situation开发者_Python百科 as following:

  1. user starts new activity - A (which I don't want to put on stack)
  2. user starts new activity (B) from A
  3. user presses BACK button from B
  4. 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

0

精彩评论

暂无评论...
验证码 换一张
取 消