I implemented for Android 3+ devices navigation of views trough ActionBar NavigationMode (DROP_DOWN_LIST).
getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.action_list, android.R.layout.simple_spinner_dropdown_item);
getActionBar().setListNavigationCallbacks(mSpinnerAdapter, new OnNavigationListener() {
@Override
public boolean onNavigationItemSelected(int index, long arg1) {
if(index == 0)
selectHomeView();
else
selectMainView();
return true;
}
});
This works as intended, but on orientation changes, the onNavigationItemSelected is called again with index = 0, returning my Activity to the first View.
How can I keep this state? And don't let onNavigationItem be called with index 0 onCreate?
EDIT:
Following Kirill answer, there's possible to store the current inedx, but there's a third view that ins't selectable trough NavigationList, and if I don't call setNavigationItemSelected after onCreate this will automatically fires with index = 0, returning the application to the first view.
This is my problem.