Reputation: 1046
I have an application first showing a login screen which on a succesful login changes to a tab view with 3 tabs. Each tab is containing a different activity. When I switch between the tabs I would like the back button to return to the previous tab instead of the login screen.
How should the be done? I'm considering implementing onBackPressed on the tab view and remembering the tab-stack manually but I don't feel that is the right approach.
Upvotes: 1
Views: 3374
Reputation: 1026
Let say you have tabs created in class called Main.java. Create there method like this:
public void switchTab(int tab) {
tabHost.setCurrentTab(tab);
}
which will change current tab. Next in activity where you want to change navigation insert the following code:
@Override
public void onBackPressed() {
Main m = (Main)getParent();
m.switchTab(0);
}
This should work.
Upvotes: 3