Activity和Fragment的生命周期
2020-06-30 本文已影响0人
hahauha
1、activity嵌套frament ,生命周期方法执行顺序
activity和fragment生命周期方法.png2、横竖屏切换activity生命周期方法调用情况(android10)
(1)不设置Activity的android:configChanges
打开activity
>>>>>>>ui.HomeActivity: onCreate()
>>>>>>>ui.HomeActivity: onStart()
>>>>>>>ui.HomeActivity: onResume()
切横屏
>>>>>>>ui.HomeActivity: onPause()
>>>>>>>ui.HomeActivity: onStop()
>>>>>>>ui.HomeActivity: onDestroy()
>>>>>>>ui.HomeActivity: onCreate()
>>>>>>>ui.HomeActivity: onStart()
>>>>>>>ui.HomeActivity: onResume()
切回竖屏
>>>>>>>ui.HomeActivity: onPause()
>>>>>>>ui.HomeActivity: onStop()
>>>>>>>ui.HomeActivity: onDestroy()
>>>>>>>ui.HomeActivity: onCreate()
>>>>>>>ui.HomeActivity: onStart()
>>>>>>>ui.HomeActivity: onResume()
(2)设置Activity的 android:configChanges="orientation"
切换横竖屏只执行了
>>>>>>>ui.HomeActivity: onConfigurationChanged()
(3)设置Activity的android:configChanges=”orientation |keyboardHidden|screenSize”
切换横竖屏只执行了
>>>>>>>ui.HomeActivity: onConfigurationChanged()
注意
Android 3.2(API 13),设置android:configChanges="orientation|keyboardHidden"起作用,
Android 3.2(API 13)之后,还必须设置"screenSize"
android:configChanges="keyboardHidden|orientation|screenSize",否则不会调用onConfigurationChanged()方法
3、按home,黑屏时,activity和fragment生命周期方法执行情况
>>>>>>>OneFragment: onPause()
>>>>>>>ui.HomeActivity: onPause()
>>>>>>>OneFragment: onStop()
>>>>>>>ui.HomeActivity: onStop()
恢复
>>>>>>>OneFragment: onStart()
>>>>>>>ui.HomeActivity: onStart()
>>>>>>>ui.HomeActivity: onResume()
>>>>>>>OneFragment: onResume()