activity和fragment生命周期

该activity有一个默认的Fragment

经过实例测试在不同场景中的生命周期方法调用如下


1.开始运行:onCreate(activity)--> onStart(activity) --> onAttach(fragment) --> onCreate(fragment) --> onCreateView(fragment) --> onViewCreated(fragment) --> onActivityCreated(fragment) --> onStart(fragment) -->onResume(activity) --> onPostResume(activity)


2.屏幕锁定:onPause(activity)--> onPause(fragment) --> onStop(activity) --> onStop(fragment) --> 


3.重新回到应用中:onRestart(activity)--> onStart(activity) --> onStart(fragment) --> onResume(activity) --> onPostResume(activity)


4.退出:onPause(activity) --> onPause(fragment) --> onStop(activity) --> onStop(fragment) --> onDestroy(activity)
--> onDestroyView(fragment) --> onDestroy(fragment) --> onDetach(fragment)

你可能感兴趣的:(activity和fragment生命周期)