第一次启动
MainActivity: --1--onCreate
MainActivity: --2--onStart
MainActivity: --3--onResume
跳到其他Activity
MainActivity: --4--onPause
MainActivity: --9--onSaveInstanceState
MainActivity: --5--onStop
返回键返回
MainActivity: --6--onRestart
MainActivity: --2--onStart
MainActivity: --3--onResume
接电话
MainActivity: --4--onPause
MainActivity: --9--onSaveInstanceState 有延迟
挂电话
MainActivity: --3--onResume
按返回键推出到Android界面
MainActivity: --4--onPause
MainActivity: --5--onStop
MainActivity: --7--onDestroy
重新启动
MainActivity: --1--onCreate
MainActivity: --2--onStart
MainActivity: --3--onResume
旋转屏幕
MainActivity: --4--onPause
MainActivity: --9--onSaveInstanceState
MainActivity: --5--onStop
MainActivity: --7--onDestroy
MainActivity: --1--onCreate
MainActivity: --2--onStart
MainActivity: --8--onRestoreInstanceState
MainActivity: --3--onResume
按Home键
MainActivity: --4--onPause
MainActivity: --9--onSaveInstanceState
MainActivity: --5--onStop
按APP图标开启
MainActivity: --6--onRestart
MainActivity: --2--onStart
MainActivity: --3--onResume
按Power键,关屏幕
MainActivity: --4--onPause
MainActivity: --9--onSaveInstanceState
MainActivity: --5--onStop
按Power键,开屏幕
MainActivity: --6--onRestart
MainActivity: --2--onStart
MainActivity: --3--onResume
按方块键
MainActivity: --4--onPause
MainActivity: --9--onSaveInstanceState
MainActivity: --5--onStop
按方块键,重新回到App
MainActivity: --6--onRestart
MainActivity: --2--onStart
MainActivity: --3--onResume
public class MainActivity extends AppCompatActivity {
private final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i(TAG, "--1--onCreate");
Button bt = (Button) findViewById(R.id.button);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, NewActivity.class);
startActivity(intent);
}
});
}
@Override
protected void onStart() {
super.onStart();
Log.i(TAG, "--2--onStart");
}
@Override
protected void onResume() {
super.onResume();
Log.i(TAG, "--3--onResume");
}
@Override
protected void onPause() {
super.onPause();
Log.i(TAG, "--4--onPause");
}
@Override
protected void onStop() {
super.onStop();
Log.i(TAG, "--5--onStop");
}
@Override
protected void onRestart() {
super.onRestart();
Log.i(TAG, "--6--onRestart");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.i(TAG, "--7--onDestroy");
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
Log.i(TAG, "--8--onRestoreInstanceState");
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Log.i(TAG,"--9--onSaveInstanceState");
}
}