生命周期状态
生命周期方法
Activity中的回调方法具体如下:
- onCreate():Activity创建时调用,通常做一些初始化设置
- onStart() :Activity即将可见时调用
- onResume():Activity获取焦点时调用
- onPause():当前Activity被其他Activity覆盖或者屏幕锁屏时调用
- onStop():Activity对用户不可见时调用
- onDestroy():Activity销毁时调用
- onRestart():Activity从停止状态到再次启动时调用
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.v("myLog","调用onCreate()");
}
@Override
protected void onStart() {
super.onStart();
Log.v("myLog","调用onStart()");
}
@Override
protected void onResume() {
super.onResume();
Log.v("myLog","调用onResume()");
}
@Override
protected void onPause() {
super.onPause();
Log.v("myLog","调用onPause()");
}
@Override
protected void onStop() {
super.onStop();
Log.v("myLog","调用onStop()");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.v("myLog","调用onDestroy()");
}
@Override
protected void onRestart() {
super.onRestart();
Log.v("myLog","调用onRestart()");
}