• 一个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
    作者:Asion Tang
    凡是没有注明[转载]的文章,本Blog发表的文章版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    什么是RESTFUL?REST的请求方法有哪些,有什么区别?
    post提交的数据有哪几种编码格式?能否通过URL参数获取用户账户密码
    什么是jsp?jsp的内置对象有哪些?
    Session和Cookie的区别
    全面系统讲解CSS工作应用+面试一步搞定
    CSS实例:翻转图片、滚动图片栏、打开大门
    【HTML5版】导出Table数据并保存为Excel
    通过HTML5的getUserMedia实现拍照功能
    Day 19: EmberJS 入门指南
    18个基于 HTML5 Canvas 开发的图表库
  • 原文地址:https://www.cnblogs.com/AsionTang/p/3483695.html
Copyright © 2020-2023  润新知