Stay on current tab after orientation change Actionbar Android

android, android-actionbar

Solution

You can actually do this very easily using onSavedInstanceState:

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    int i = getActionBar().getSelectedNavigationIndex();
    outState.putInt("index", i);
}

Then include this in your onCreate() method:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
            ...
    if(savedInstanceState != null) {
        int index = savedInstanceState.getInt("index");
        getActionBar().setSelectedNavigationItem(index);
    }
}

Problem

In my application the selected tab in the actionbar is set to the first one when the orientation is changed, i'd like it to stay on the selected tab, and not jump to the first tab in line...

Original source

Related problems