Reputation: 459
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
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:
remember to save the state(override the onSavedInstanceState()
and save the tab state) to make you activity works right after restore from onPause()
.
read about android's recommended navigation style here. What you designed is a little bit different from what android suggests.
Upvotes: 1