- 初次打开FragmentActivity时
1 VisitTaskManagerActivity(8473): onCreate 2 VisitTaskManagerActivity(8473): onStart 3 VisitTaskManagerActivity(8473): onResume 4 5 Fragment1(8473): onAttach 6 Fragment1(8473): onCreate 7 Fragment1(8473): onCreateView 8 Fragment1(8473): onViewCreated 9 Fragment1(8473): onActivityCreated10 Fragment1(8473): onViewStateRestored11 Fragment1(8473): onStart12 Fragment1(8473): onResume13 14 Fragment2(8473): onAttach15 Fragment2(8473): onCreate16 Fragment2(8473): onCreateView17 Fragment2(8473): onViewCreated18 Fragment2(8473): onActivityCreated19 Fragment2(8473): onViewStateRestored20 21 Fragment3(8473): onAttach22 Fragment3(8473): onCreate23 Fragment3(8473): onCreateView24 Fragment3(8473): onViewCreated25 Fragment3(8473): onActivityCreated26 Fragment3(8473): onViewStateRestored27 28 Fragment4(8473): onAttach29 Fragment4(8473): onCreate30 Fragment4(8473): onCreateView31 Fragment4(8473): onViewCreated32 Fragment4(8473): onActivityCreated33 Fragment4(8473): onViewStateRestored34 35 Fragment2(8473): onStart36 Fragment2(8473): onResume37 38 Fragment3(8473): onStart39 Fragment3(8473): onResume40 41 Fragment4(8473): onStart42 Fragment4(8473): onResume
- 系统按HOME键到桌面时
VisitTaskManagerActivity(7275): onPauseFragment1(7275): onPauseFragment2(7275): onPauseFragment3(7275): onPauseFragment4(7275): onPauseVisitTaskManagerActivity(7275): onStopFragment1(7275): onStopFragment2(7275): onStopFragment3(7275): onStopFragment4(7275): onStop
- 从桌面返回FragmentActivity时
1 VisitTaskManagerActivity(8473): onStart 2 Fragment1(8473): onStart 3 Fragment2(8473): onStart 4 Fragment3(8473): onStart 5 Fragment4(8473): onStart 6 VisitTaskManagerActivity(8473): onResume 7 Fragment1(8473): onResume 8 Fragment2(8473): onResume 9 Fragment3(8473): onResume10 Fragment4(8473): onResume
- 自动切换横竖屏时(或者按HOME键到桌面时,杀掉进程,再从桌面返回FragmentActivity时)
VisitTaskManagerActivity(8504): onCreateFragment1(8504): onAttachFragment1(8504): onCreateFragment2(8504): onAttachFragment2(8504): onCreateFragment3(8504): onAttachFragment3(8504): onCreateFragment4(8504): onAttachFragment4(8504): onCreateVisitTaskManagerActivity(8504): onStartFragment1(8504): onCreateViewFragment1(8504): onViewCreatedFragment1(8504): onActivityCreatedFragment1(8504): onViewStateRestoredFragment2(8504): onCreateViewFragment2(8504): onViewCreatedFragment2(8504): onActivityCreatedFragment2(8504): onViewStateRestoredFragment3(8504): onCreateViewFragment3(8504): onViewCreatedFragment3(8504): onActivityCreatedFragment3(8504): onViewStateRestoredFragment4(8504): onCreateViewFragment4(8504): onViewCreatedFragment4(8504): onActivityCreatedFragment4(8504): onViewStateRestoredFragment1(8504): onStartFragment2(8504): onStartFragment3(8504): onStartFragment4(8504): onStartVisitTaskManagerActivity(8504): onResumeFragment1(8504): onResumeFragment2(8504): onResumeFragment3(8504): onResumeFragment4(8504): onResume
在此使用onSaveInstanceState来保存临时状态的需留意的:
- 根据官方文档的说明,onSaveInstanceState的调用时机为非正常finish()情况下,可能在onPause到onDestroy之间的任意时刻调用。