home button/long press breaks activity stack
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
- Remove singleinstance launchmode from A
- 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.
精彩评论