Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. ## Activity + Fragment Life Cycles
  2.  
  3. - [Basic](#basic)
  4. - [Screen rotation, regular](#screen-rotation-regular)
  5.  
  6. Note: `/A` = activity calls , `/F` = fragment calls
  7.  
  8. ### Basic
  9. ```
  10. # Launch from home screen
  11. D/A: Activity.constructor()
  12. D/A: onCreate() : savedInstanceState = [null]
  13. D/A: onCreateView() ## multiple calls for different non-fragment parts
  14. D/A: onContentChanged()
  15. D/F: Fragment.constructor()
  16. D/F: onAttach()
  17. D/A: onAttachFragment() : fragment = [the fragment created]
  18. D/F: onCreate() : savedInstanceState = [null]
  19. D/F: onCreateView() : savedInstanceState = [null]
  20. V/F: |- isVisible = false
  21. D/A: onCreateView() ## multiple, to setup the view for the fragment
  22. D/F: onViewCreated() : savedInstanceState = [null]
  23. V/F: |- isVisible = false
  24. D/F: onActivityCreated() : savedInstanceState = [null]
  25. D/F: onViewStateRestored() : savedInstanceState = [null]
  26. D/F: onStart()
  27. D/A: onStart()
  28. D/A: onPostCreate() : savedInstanceState = [null]
  29. D/A: onStateNotSaved()
  30. D/A: onResume()
  31. D/F: onResume()
  32. V/F: |- isVisible = false ## the view remains not visible even at onResume()
  33. D/A: onResumeFragments()
  34. D/A: onPostResume()
  35. # The App is brought up and visible
  36.  
  37. # Press home screen button to hide the app
  38. D/F: onPause()
  39. D/A: onPause()
  40. D/F: onStop()
  41. D/A: onStop()
  42. D/F: onSaveInstanceState() : outState = [Bundle[{}]]
  43. D/A: onSaveInstanceState() : outState = [some states from the framework]
  44.  
  45. # Brought back from recent app list
  46. D/A: onRestart()
  47. D/F: onStart()
  48. V/F: |- isVisible = true
  49. D/A: onStart()
  50. D/A: onStateNotSaved()
  51. D/A: onResume()
  52. D/F: onResume()
  53. V/F: |- isVisible = true
  54. D/A: onResumeFragments()
  55. D/A: onPostResume()
  56.  
  57. # Press home screen, then swipes the app away from recent app list
  58. D/F: onStop()
  59. D/A: onStop()
  60. D/F: onSaveInstanceState() : outState = [Bundle[{}]]
  61. D/A: onSaveInstanceState() : outState = [some states from the framework]
  62. D/F: onDestroyView()
  63. D/F: onDestroy()
  64. D/F: onDetach()
  65. D/A: onDestroy()
  66.  
  67. ```
  68.  
  69. ### Screen Rotation (regular)
  70. The default case the fragment is not retained, i.e., `Fragment.setRetainInstance(false)`.
  71.  
  72. It's basically the same as if the activity/fragment is created from scratch, except
  73. - a non-null instanced state to all applicable methods
  74. - The fragment is created and attached a bit earlier, before `Activity.onCreate()` is called.
  75.  
  76. ```
  77. # the app is visible, with last life cycle method
  78. # being Activity.onPostResume()
  79.  
  80. # screen rotated
  81. D/F: onPause()
  82. D/A: onPause()
  83. D/F: onStop()
  84. D/A: onStop()
  85. D/F: onSaveInstanceState() : outState = [Bundle[{}]]
  86. D/A: onSaveInstanceState() : outState = [some states from the framework]
  87. D/F: onDestroyView()
  88. D/F: onDestroy()
  89. D/F: onDetach()
  90. D/A: onDestroy()
  91. D/A: Activity.constructor()
  92. D/F: Fragment.constructor()
  93. D/F: onAttach()
  94. D/A: onAttachFragment() : fragment = [fragment just created]
  95. D/F: onCreate() : savedInstanceState = [some states from the framework]
  96. D/A: onCreate() : savedInstanceState = [some states from the framework]
  97. D/A: onCreateView() ## multiple calls for different non-fragment parts
  98. D/A: onContentChanged()
  99. D/F: onCreateView() : savedInstanceState = [some states from the framework]
  100. D/A: onCreateView() ## multiple, to setup the view for the fragment
  101. D/F: onViewCreated() : savedInstanceState = [some states from the framework]
  102. D/F: onActivityCreated() : savedInstanceState = [some states from the framework]
  103. D/F: onViewStateRestored() : savedInstanceState = [some states from the framework]
  104. D/F: onStart()
  105. D/A: onStart()
  106. D/A: onRestoreInstanceState() : savedInstanceState = [some states from the framework]
  107. D/A: onPostCreate() : savedInstanceState = [some states from the framework]
  108. D/A: onStateNotSaved()
  109. D/A: onResume()
  110. D/F: onResume()
  111. D/A: onResumeFragments()
  112. D/A: onPostResume()
  113. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement