开发者

home button/long press breaks activity stack

开发者 https://www.devze.com 2023-02-13 17:15 出处:网络
I have A,B activities.. A is the launcher activity. User goes from A -> B User presses home button -> Launches browser -> long press on home button -> selects my application -> now B is on stack an

I have A,B activities..

A is the launcher activity.

User goes from A -> B

User presses home button -> Launches browser -> long press on home button -> selects my application -> now B is on stack and hitting back button does not take him from B -> A.

A is singleInstance activity.

I want A activity to be accessible from anywhere with help of 开发者_高级运维back button.

Is there a simple way OR do I have to catch back button event and start A activity.

And since A is single instance it will be fetched from instance which is already there on stack/dvm.

Please suggest...


You will need to catch the back button and call A if you want to start A every time the user presses back.

But make sure you have a good reason to so the same as this breaks the regular flow of the app and unless handled correctly one might create an looped/screwed ( :-) ) activity stack.

It would be better if you launch Activity A from the menu.


You shouldn't use singleInstance in activity unless you know what you're doing. singleInstance creates new Task and causes unintentionall behavior in your solution.

Read this article. It will give you more information how to handle Tasks and Back Stacks.

Or write more what you want to implement.


It woked after doing following

  1. Remove singleinstance launchmode from A
  2. Whenever starting activity A make sure you have FLAG_ACTIVITY_CLEAR_TOP launchmode. If you dont do this there will be long chain of activities after some time.
0

精彩评论

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