我正在使用操作栏选项卡导航,当我旋转屏幕时,我得到 IndexOutOfBoundsException
根据logcat问题在getSupportActionBar().setSelectedNavigationItem(
savedInstanceState.getInt(STATE_SELECTED_NAVIGATION_ITEM));
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
// Restore the previously serialized current tab position.
if (savedInstanceState.containsKey(STATE_SELECTED_NAVIGATION_ITEM)) {
getSupportActionBar().setSelectedNavigationItem(
savedInstanceState.getInt(STATE_SELECTED_NAVIGATION_ITEM));
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
// Serialize the current tab position.
outState.putInt(STATE_SELECTED_NAVIGATION_ITEM, getSupportActionBar()
.getSelectedNavigationIndex());
}
编辑
我发现了问题。我使用 AsyncTask 收集将显示在选项卡中的所有信息,并在onPostExecute
.
onRestoreInstanceState
之前调用过,onPostExecute
所以标签计数仍然为 0。