views:

81

answers:

2

Is there a possibility to navigate between Activities tabs in TabHost using back button? When I press it, I go out of the main Activity to the previous one.

A: 

That's the way a TabHost works. It contains the tabs within itself, so hitting the Back button is backing out of the TabHost, not the Activity contained within a particular tab.

I suppose there's probably some way you could override the Back button and fake it.

kiswa
+2  A: 

You could keep track of the previously selected tab using the TabHost's setOnTabChangedListener() method and then override your Activity's onBackPressed() method to setCurrentTabByTag() on the TabHost, but think really really hard before you do this, since it's not at all the expected behavior for Android users interacting with a tabbed activity.

Name one other popular Android application that does this. Then explain why your app will be different than these and how changing the expected behavior will do anything other than confuse and annoy users. If you can do that, have at it; otherwise, think long and hard about whether tabs are even the right metaphor for your app. Perhaps the Dashboard pattern (item 3 at the link) is more suitable for your case?

Yoni Samlan