I have an app with a MainActivity
and ChildAaActivity
and ChildBbActivity
.
MainActivity can send us to either of the Child activities and the user can move between the two Child activities as often as they want.
However, there must only be one instance of each of these activities.
The problem is, if I make the child activities singleInstance
, then they are all separate tasks and switching to another app and back to the child means that onBackPress
I exit the app (when I should return to MainActivity)
If I leave launchMode
as standard, then I get multiple instances of the child activities, especially when moving back and forth between the two children.
If I use singleTop
, then I have both problems
If I use noHistory
on the children I can't freely move between them (first back press would return me to MainActivity)
Using isTaskRoot()
obviously wont work with singleInstance
to fix the app exiting bug, because it will always be true (and isn't useful for the other scenarios)
How should I correctly achieve the behaviour I need?
- Only one instance of each Activity in the back stack
- All in the same task / don't exit onBackPress after switching apps