Activity生命周期图:
下面以一个实例来解析,实例APP运行,进入MainActivity,
点击Send Button以后进入MessgaeActivity
当第一次运行App,进入MainActivity时,执行顺序如下
1 Mainactivity.onCreate()
2 Mainactivity.onStart()
3 Mainactivity.onResume()
当点击Send从MainActivity跳转到MessageActivity时,执行顺序如下
1 Mainactivity.onPause()
2 MessageActivity.onCreate()
3 MessageActivity.onStart()
4 MessageActivity.onResume()
5 Mainactivity.onStop()
当点击返回按钮从MessageActivity跳转到MainActivity时,执行顺序如下
1 MessageActivity.onPause()
2 Mainactivity.onDestroy()
3 Mainactivity.onCreate()
4 Mainactivity.onStart()
5 Mainactivity.onResume()
6 MessageActivity.onStop()
7 MessageActivity.onDestroy()
当打开notification时(当前处于ManinActivity),执行顺序如下
1 Mainactivity.onPause()
2 Mainactivity.onStop()
当从notification返回到ManinActivity时,
1 Mainactivity.onRestart()
2 Mainactivity.onStart()
3 Mainactivity.onResume()
当从MainActivity退出时(系统默认的返回),执行顺序如下
1 Mainactivity.onPause()
当退出以后再次运行MainActivity,执行顺序如下
1 Mainactivity.onStop()
2 Mainactivity.onDestroy()
3 Mainactivity.onCreate()
4 Mainactivity.onStart()
5 Mainactivity.onResume()