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.
Asked
Active
Viewed 97 times
0

J Jiang
- 1,452
- 10
- 14

Vishnu Prabhu
- 449
- 1
- 5
- 19
1 Answers
1
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 fromonPause()
.read about android's recommended navigation style here. What you designed is a little bit different from what android suggests.

J Jiang
- 1,452
- 10
- 14