String activityState;
@Override
public void onCreate(Bundle savedInstanceState) {
// call the super class onCreate to complete the creation of activity like
// the view hierarchy
super.onCreate(savedInstanceState);
// recovering the instance state
if (savedInstanceState != null) {
activityState = savedInstanceState.getString(STATE_KEY);
}
setContentView(R.layout.main_activity);
mTextView = (TextView) findViewById(R.id.text_view);
}
///仅当存在先前使用// onSaveInstanceState()保存的已保存实例时,才调用此回调。我们在onCreate()中还原某些状态,而在这里我们可以选择还原//其他状态,可能在onStart()完成后可用。// savedInstanceState捆绑包与onCreate()中使用的捆绑包相同。
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
mTextView.setText(savedInstanceState.getString(STATE_KEY));
}
// invoked when the activity may be temporarily destroyed, save the instance
//state here
//this method will be called before onstop
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putString(STATE_KEY, activityState);
// call superclass to save any view hierarchy
super.onSaveInstanceState(outState);
}