Vishnu Prabhu
Vishnu Prabhu

Reputation: 459

Android Actionbar tabs Navigation

I am a beginner in android. I have created Tabs using ActionBar tabs. Now I want to implement, when the user in in first tab and clicks back Button activity should close or when the user is in second tab, he clicks the backbutton the app should show the first tab, which will make it as the home tab. I tried using popupbackstack() but it always closes the activity no matter what tab i am in. please guide me. Thanks in advance.

Upvotes: 0

Views: 98

Answers (1)

J Jiang
J Jiang

Reputation: 1512

The easiest way would be record the tab state (i.e., which tab is showing) in the host activity, and override the onBackPressed() method to do what you want.

Some tips:

  1. remember to save the state(override the onSavedInstanceState() and save the tab state) to make you activity works right after restore from onPause().

  2. read about android's recommended navigation style here. What you designed is a little bit different from what android suggests.

Upvotes: 1

Related Questions