以从MainActivity启动SecondActivity为例,分析生命周期的变化:
- MainActivity启动后
MainActivity onCreate
MainActivity onStart
MainActivity onResume - 通过startActivity启动SecondActivity后
MainActivity onPause
SecondActivity onCreate
SecondActivity onStart
SecondActivity onResume
MainActivity onStop - 从SecondActivity返回后
SecondActivity onPause
MainActivity onStart
MainActivity onResume
SecondActivity onStop
SecondActivity onDestroy
总结:
- 从MainActivity启动SecondActivity时,MainActivity先onPause、等SecondActivity执行onResume后,MainActivity再执行onStop;
- 从SecondActivity返回时,SecondActivity先onPause、等MainActivity执行完onResume后,SecondActivity在onStop。
网友评论