Draiken
Draiken

Reputation: 3815

Android TabHost.setCurrentTab() not working

I have a TabActivity that I am having problems after the device changes orientation. Followed some places on how to keep the current tab open after the change, but even tho I do get the correct tab number, it always sets it back to 0.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    int currentTab = 1;
    if (savedInstanceState != null)
        currentTab = savedInstanceState.getInt("tabNumber");

    tabHost = getTabHost(); // (TabHost) findViewById(android.R.id.tabhost);
    createTabs(tabHost);
    tabHost.setCurrentTab(currentTab);
}

protected void onSaveInstanceState(Bundle outState) {
    outState.putInt("tabNumber", getTabHost().getCurrentTab());
    super.onSaveInstanceState(outState);
}

Am I doing something wrong here?

Upvotes: 0

Views: 1560

Answers (1)

lacas
lacas

Reputation: 14066

add this to yout manifest file

..

activity android:name="youractivity"
android:configChanges="orientation|keyboardHidden"

...

Leslie

Upvotes: 2

Related Questions