标签:oncreate 出栈 onstop ace art mit replace 操作 child
此种情况表示不会预先加载其他的Fragment,仅仅加载第一个Fragment,其生命周期如下:
Test fragment 0 onAttach
Test fragment 0 onCreate
Test fragment 0 onCreateView
Test fragment 0 OnActivityCreated
Test fragment 0 onStart
Test fragment 0 onResume
这俩个Fragment的生命周期如下:
Test fragment 1 onAttach
Test fragment 1 onCreate
Test fragment 1 onCreateView
Test fragment 1 OnActivityCreated
Test fragment 1 onStart
Test fragment 0 onPause
Test fragment 1 onResume
等第二个Fragment执行到onStart
后,执行第一个Fragment的onPause
函数。
前后两个Fragment的生命周期如下:
Test fragment 1 onPause
Test fragment 0 onResume
先执行当前Fragment的onPause
函数,然后执行原来的Fragment的onResume
函数。
此种情况将会根据offscreenPageLimit
的值加载不可见的Fragment,这几个Fragment的生命周如下:
Test fragment 0 onAttach
Test fragment 0 onCreate
Test fragment 0 onCreateView
Test fragment 0 OnActivityCreated
Test fragment 0 onStart
Test fragment 0 onResume
Test fragment 1 onAttach
Test fragment 1 onCreate
Test fragment 1 onCreateView
Test fragment 1 OnActivityCreated
Test fragment 1 onStart
Test fragment 2 onAttach
Test fragment 2 onCreate
Test fragment 2 onCreateView
Test fragment 2 OnActivityCreated
Test fragment 2 onStart
这几个Fragment会依次执行其生命周期,但是只有可见的Fragment执行到了onResume
函数。
入栈调用的是replace()
函数。
commitChildFragment操作在Container Fragment的onCreateView
函数中执行,这两个Fragment的生命周期如下:
container fragment onAttach
container fragment onCreate
container fragment onCreateView
container fragment onActivityCreated
Child fragment 0 onAttach
Child fragment 0 onCreate
Child fragment 0 onCreateView
Child fragment 0 OnActivityCreated
container fragment onStart
Child fragment 0 onStart
container fragment onResume
Child fragment 0 onResume
虽然commitChildFragment
在onCreateView
执行,但是child Fragment真正地开始执行生命周期是在container Fragment
的onActivityCreated
函数之后。
前后两个Fragment生命周期如下,Child Fragment 0
先入栈,Child Fragment 1
后入栈。
Child fragment 1 onAttach
Child fragment 1 onCreate
Child fragment 0 onPause
Child fragment 0 onStop
Child fragment 0 onDestroyView
Child Fragment 1 onCreateView
Child fragment 1 OnActivityCreated
Child fragment 1 onStart
Child fragment 1 onResume
Child fragment 1 onPause
Child fragment 1 onStop
Child fragment 1 onDestroyView
Child fragment 1 onDestroy
Child fragment 1 onDetach
Child fragment 0 onCreateView
Child fragment 0 OnActivityCreated
Child fragment 0 onStart
Child fragment 0 onResume
标签:oncreate 出栈 onstop ace art mit replace 操作 child
原文地址:https://www.cnblogs.com/ijkzen/p/14281842.html