在按下 home 并重新打开应用程序后,我正在尝试恢复我以前的状态,Activity
所以我正在保存我需要的内容onSaveInstanceState
:
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(STATE_ACTIVE_VIEW_ID, mActiveViewId);
Log.v(TAG, this.toString() + " onSaveInstanceState");
}
那就是所谓的,但在onCreate
里面Bundle
总是null
。
这是 OnCreate():
@Override
public void onCreate(Bundle inState) {
super.onCreate(inState);
setContentView(R.layout.main);
setMenuDrawer();
if (inState != null) {
int activeViewID = inState.getInt(STATE_ACTIVE_VIEW_ID);
View activeView = findViewById(activeViewID);
menuDrawer.setActiveView(activeView);
switchSelectedFragment(activeView);
Log.v(TAG, this.toString() + " onCreate " + inState.toString());
} else {
switchSelectedFragment(findViewById(R.id.homeView));
}
Log.v(TAG, this.toString() + " onCreate");
}