一个FragmentActivity多个Fragment的生命周期事件记录

  • 初次打开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): onActivityCreated
    10 Fragment1(8473): onViewStateRestored
    11 Fragment1(8473): onStart
    12 Fragment1(8473): onResume
    13 
    14 Fragment2(8473): onAttach
    15 Fragment2(8473): onCreate
    16 Fragment2(8473): onCreateView
    17 Fragment2(8473): onViewCreated
    18 Fragment2(8473): onActivityCreated
    19 Fragment2(8473): onViewStateRestored
    20 
    21 Fragment3(8473): onAttach
    22 Fragment3(8473): onCreate
    23 Fragment3(8473): onCreateView
    24 Fragment3(8473): onViewCreated
    25 Fragment3(8473): onActivityCreated
    26 Fragment3(8473): onViewStateRestored
    27 
    28 Fragment4(8473): onAttach
    29 Fragment4(8473): onCreate
    30 Fragment4(8473): onCreateView
    31 Fragment4(8473): onViewCreated
    32 Fragment4(8473): onActivityCreated
    33 Fragment4(8473): onViewStateRestored
    34 
    35 Fragment2(8473): onStart
    36 Fragment2(8473): onResume
    37 
    38 Fragment3(8473): onStart
    39 Fragment3(8473): onResume
    40 
    41 Fragment4(8473): onStart
    42 Fragment4(8473): onResume
    View Code
  • 系统按HOME键到桌面时
    VisitTaskManagerActivity(7275): onPause
    Fragment1(7275): onPause
    Fragment2(7275): onPause
    Fragment3(7275): onPause
    Fragment4(7275): onPause
    VisitTaskManagerActivity(7275): onStop
    Fragment1(7275): onStop
    Fragment2(7275): onStop
    Fragment3(7275): onStop
    Fragment4(7275): onStop
    View Code
  • 从桌面返回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): onResume
    10 Fragment4(8473): onResume
    View Code
  • 自动切换横竖屏时(或者按HOME键到桌面时,杀掉进程,再从桌面返回FragmentActivity时)
    VisitTaskManagerActivity(8504): onCreate
    
    Fragment1(8504): onAttach
    Fragment1(8504): onCreate
    
    Fragment2(8504): onAttach
    Fragment2(8504): onCreate
    
    Fragment3(8504): onAttach
    Fragment3(8504): onCreate
    
    Fragment4(8504): onAttach
    Fragment4(8504): onCreate
    
    VisitTaskManagerActivity(8504): onStart
    
    Fragment1(8504): onCreateView
    Fragment1(8504): onViewCreated
    Fragment1(8504): onActivityCreated
    Fragment1(8504): onViewStateRestored
    
    Fragment2(8504): onCreateView
    Fragment2(8504): onViewCreated
    Fragment2(8504): onActivityCreated
    Fragment2(8504): onViewStateRestored
    
    Fragment3(8504): onCreateView
    Fragment3(8504): onViewCreated
    Fragment3(8504): onActivityCreated
    Fragment3(8504): onViewStateRestored
    
    Fragment4(8504): onCreateView
    Fragment4(8504): onViewCreated
    Fragment4(8504): onActivityCreated
    Fragment4(8504): onViewStateRestored
    
    Fragment1(8504): onStart
    Fragment2(8504): onStart
    Fragment3(8504): onStart
    Fragment4(8504): onStart
    
    VisitTaskManagerActivity(8504): onResume
    Fragment1(8504): onResume
    Fragment2(8504): onResume
    Fragment3(8504): onResume
    Fragment4(8504): onResume
    View Code

在此使用onSaveInstanceState来保存临时状态的需留意的:

  1. 根据官方文档的说明,onSaveInstanceState的调用时机为非正常finish()情况下,可能在onPause到onDestroy之间的任意时刻调用。
    onSaveInstanceState | Android Developers

 

 

 

posted @ 2013-12-20 13:07  Asion Tang  阅读(1262)  评论(0编辑  收藏  举报