1

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();
    }
Jason Plank
  • 2,336
  • 5
  • 31
  • 40
Dan
  • 179
  • 1
  • 4
  • 8

1 Answers1

4

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.

Community
  • 1
  • 1
AlexKorovyansky
  • 4,873
  • 5
  • 37
  • 48
  • Thank you very much for your response. I updated what I tried (that does not work). – Dan Feb 11 '11 at 10:54