0

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.

1 Answer 1

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:

  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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.