I have a TabActivity that is the “base” Activity in my application. From the TabActivity a user can navigate through new Activities that are not a part of the original TabHost (I’m not messing around with TabGroups or anything like that).
My application also has a global options menu, from which a user should be able to navigate back to the original TabActivity and select a certain tab. For example, if the user selected the left-most options menu item, they would go to the left-most tab in the original TabActivity.
How can I accomplish this behavior? I do not want to start a new TabActivity because the original TabActivity has data propogated on it like Map points and a ListView. Ideally I would like to go back to that specific TabActivity. This movement can also occur at any point in the lifecycle, e.g.:
Original TabActivity -> Activity1 -> Activity2 -> Activity3 -> Activity n ->Back to Original TabActivity
Original TabActivity -> Activity1 -> Back to Original TabActivity
There can be any number of Activities launched in between the navigation. Therefore, calling finish() in the current Activity won’t satisfy this (as far as I know…).
My questions/concerns:
- Primarily, how to accomplish this.
- It is possible that the original
TabActivitycould be removed from the stack due to memory, correct? If so, how to deal with that? I assume if I figured out a way to locate the originalTabActivityI could just do a check for null and if it’s not there, start a newTabActivity.
Figured this out. You should use
launchMode="singleTask"in your Manifest for the specificActivitythat you wish to switch back to. According to the Dev docs this routes back to that specificActivityif it exists.So, in my Manifest, I have:
Then, in any
Activitywhere you want to switch back to thatTabActivity, just call a normalIntent. You can also useputExtra()to tell theTabActivityto switch to a new tab.In a sub Activity:
This will either launch a new
MainTabsActivityif the stack doesn’t have one or switch back to the old instance because of thelaunchMode="singleTask"parameter.In order to provide the tab switching functionality, override
onNewIntent(Intent intent)in your mainTabActivitylike so:I hope this helps somebody that has a similar problem.