The app has an Action Bar, the action bar has several navigation tabs on it. If someone runs the app this happens:
- Open app, view content in fragment 1 (tab 1)
- Tap tab 2, see content in fragment 2.
- Tap tab 3, see content in fragment 3
- Hit Back. The fragment vanishes, and the tab content is left empty. Hit back again, another blank fragment shows, hit back again and another blank fragment, hit back again, you exit the app.
What I want to happen is for someone to visit a series of tabs, then use Back to cycle back through them. I’ve spent hours trying to figure it out and I’m stumped. Help a guy out of his misery?
Ms. Hackborn, in another answer somewhere here in SO, really did not like what you’re aiming for IIRC. Tabs are an independent navigation metaphor. Just as pressing the BACK button in a Web browser does not magically close up tabs, nor should pressing the BACK button in an Android app. Pressing the BACK button might change the content in the current tab, before eventually exiting the app.
That being said, if your quite certain that this is the navigation you want, don’t use the built-in back stack but manage it yourself, no different than if you wanted tabs in an old-style
TabHostto vanish based on a BACK button press. You would keep tabs (pun lightly intended) of the tabs you add, then useremoveTab()orremoveTabAt()onActionBarto get rid of them. On your last tab, youronBackPressed()would chain to the superclass for normal finish-the-activity logic.