生命周期
标准流程
由A启动B的流程:
A - onPause
B - onCreate
B - onStart
B - onResume
A - onStop
在B按返回:
B - onPause
A - onRestart
A - onStart
A - onResume
B - onStop
B - onDestroy
前后台切换
保留活动情况
- onCreate
- onStart
- onResume
Home - onPause
- onSaveInstanceState
- onStop
恢复 - onRestart
- onStart
- onResume
不保留活动情况
- onCreate
- onStart
- onResume
Home - onPause
- onSaveInstanceState
- onStop
- onDestroy
恢复 - onCreate
- onStart
- onRestoreInstanceState 确实被销毁,重新创建才会执行
- onResume
锁屏
指定方向
- onCreate
- onStart
- onResume
锁屏 - onPause
- onStop
解锁 - onRestart
- onStart
- onResume
未指定方向
- onCreate
- onStart
- onResume
锁屏 - onPause
- onStop
- onDestroy
- onCreate
- onStart
- onResume
- onPause
解锁 - onResume
- onPause
- onStop
- onDestroy
- onCreate
- onStart
- onResume
横竖屏切换
由于Android版本不同生命周期会有所不同,我所打的log是Android7.0
无config
configChanges="orientation"
发现以上两种生命周期没有变化,再来试试screenSize
configChanges="screenSize"
三种情况完全没差啊,这时
configChanges="orientation|screenSize"
换Android4.4的模拟器看看
无config
没有onConfigurationChanged回调
configChanges="orientation"
还没有onConfigurationChanged回调
configChanges="screenSize"
the same
configChanges="orientation|screenSize"