1.新增键值对的键
public class QuizActivity extends AppCompatActivity {
private static final String KEY_INDEX = "index";
...
2.覆盖onSaveInstanceState(...)方法
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
Log.i(TAG, "onSaveInstanceState");
savedInstanceState.putInt(KEY_INDEX, mCurrentIndex);
}
3.在onCreate(...)方法中检查存储的bundle信息
public void onCreate(Bundle savedInstanceState){
...
if (savedInstanceState != null) {
mCurrentIndex = savedInstanceState.getInt(KEY_INDEX, 0);
}
...