本次所做为保存数据以应对设备旋转,添加代码如下:

private static final String KEY_INDEX="index";

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG,"onCreate(Bundle) called");
    setContentView(R.layout.activity_quiz);

    if (savedInstanceState!=null){
        mCurrentIndex=savedInstanceState.getInt(KEY_INDEX,0);
    }

@Override
protected void  onStart(){
    super.onStart();
    Log.d(TAG,"onStart() called");
}

@Override
protected void  onResume(){
    super.onResume();
    Log.d(TAG,"onResume() called");
}

@Override
protected void  onPause(){
    super.onPause();
    Log.d(TAG,"onPause() called");
}

@Override
public void onSaveInstanceState(Bundle savedInstanceState){
    super.onSaveInstanceState(savedInstanceState);
    Log.i(TAG,"onSaveInstanceState");
    savedInstanceState.putInt(KEY_INDEX,mCurrentIndex);
}
@Override
protected void  onStop(){
    super.onStop();
    Log.d(TAG,"onStop() called");
}

截图如下:

Android学习-第6天

相关文章:

  • 2021-04-10
  • 2021-05-30
  • 2021-07-14
  • 2021-10-30
  • 2021-04-22
  • 2021-06-14
  • 2021-07-18
  • 2021-09-01
猜你喜欢
  • 2021-10-15
  • 2021-10-03
  • 2021-10-21
  • 2021-09-23
  • 2021-09-04
  • 2021-08-12
  • 2021-08-03
相关资源
相似解决方案