Dan
Dan

Reputation: 179

How can I prevent the current tab view from being lost when rotating the screen?

I have tabhost with 4 tabs. If I (for example) open tab #3, start a simple alert dialog, and then rotate the phone a few times, it loses focus on which tab was open before, so when I press back, tab #1 shows up instead of tab #3.

I would be very grateful for a solution or any hints to solve this problem.

protected void onSaveInstanceState(Bundle outState) {   
        super.onSaveInstanceState(outState);
        saveState();
    }
    protected void onPause() {
        super.onPause();
        saveState();
    }
    protected void onResume() {
        super.onResume();
        getTabHost().setCurrentTab(currentTab);
    }   
    private void saveState(){
        currentTab=getTabHost().getCurrentTab();
    }

Upvotes: 1

Views: 2220

Answers (1)

AlexKorovyansky
AlexKorovyansky

Reputation: 4943

Did you try save state of TabHost? If not - check Reto Meier answer in this discussion.

You can save current position of TabHost using getCurrentTab at onSaveInstanceState, and restore it at onRestoreInstanceState using setCurrentTab.

Upvotes: 4

Related Questions