1
這個錯誤是我非常大的問題,我對此有更多解決方案,但是我無法解決這個問題,我在活動上有一些片段,並且通過此代碼替換片段:Android在onSaveInstanceState後無法執行此操作
if (mSelectedMenuItem != 2) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
transaction.replace(R.id.menu_containers, fragment);
transaction.commit();
}
}, duration);
}
錯誤:
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
和我onSaveInstanceState
:
@Override
protected void onSaveInstanceState(Bundle outState) {
// Bug in android version > 11
//super.onSaveInstanceState(outState);
outState.putInt("selectedMenuItem", selectedMenuItem);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
selectedMenuItem = savedInstanceState.getInt("selectedMenuItem");
}
選中此項[Fragment Transactions&Activity State Loss](http://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html) – Raghavendra