Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Activity + Fragment Life Cycles
- - [Basic](#basic)
- - [Screen rotation, regular](#screen-rotation-regular)
- Note: `/A` = activity calls , `/F` = fragment calls
- ### Basic
- ```
- # Launch from home screen
- D/A: Activity.constructor()
- D/A: onCreate() : savedInstanceState = [null]
- D/A: onCreateView() ## multiple calls for different non-fragment parts
- D/A: onContentChanged()
- D/F: Fragment.constructor()
- D/F: onAttach()
- D/A: onAttachFragment() : fragment = [the fragment created]
- D/F: onCreate() : savedInstanceState = [null]
- D/F: onCreateView() : savedInstanceState = [null]
- V/F: |- isVisible = false
- D/A: onCreateView() ## multiple, to setup the view for the fragment
- D/F: onViewCreated() : savedInstanceState = [null]
- V/F: |- isVisible = false
- D/F: onActivityCreated() : savedInstanceState = [null]
- D/F: onViewStateRestored() : savedInstanceState = [null]
- D/F: onStart()
- D/A: onStart()
- D/A: onPostCreate() : savedInstanceState = [null]
- D/A: onStateNotSaved()
- D/A: onResume()
- D/F: onResume()
- V/F: |- isVisible = false ## the view remains not visible even at onResume()
- D/A: onResumeFragments()
- D/A: onPostResume()
- # The App is brought up and visible
- # Press home screen button to hide the app
- D/F: onPause()
- D/A: onPause()
- D/F: onStop()
- D/A: onStop()
- D/F: onSaveInstanceState() : outState = [Bundle[{}]]
- D/A: onSaveInstanceState() : outState = [some states from the framework]
- # Brought back from recent app list
- D/A: onRestart()
- D/F: onStart()
- V/F: |- isVisible = true
- D/A: onStart()
- D/A: onStateNotSaved()
- D/A: onResume()
- D/F: onResume()
- V/F: |- isVisible = true
- D/A: onResumeFragments()
- D/A: onPostResume()
- # Press home screen, then swipes the app away from recent app list
- D/F: onStop()
- D/A: onStop()
- D/F: onSaveInstanceState() : outState = [Bundle[{}]]
- D/A: onSaveInstanceState() : outState = [some states from the framework]
- D/F: onDestroyView()
- D/F: onDestroy()
- D/F: onDetach()
- D/A: onDestroy()
- ```
- ### Screen Rotation (regular)
- The default case the fragment is not retained, i.e., `Fragment.setRetainInstance(false)`.
- It's basically the same as if the activity/fragment is created from scratch, except
- - a non-null instanced state to all applicable methods
- - The fragment is created and attached a bit earlier, before `Activity.onCreate()` is called.
- ```
- # the app is visible, with last life cycle method
- # being Activity.onPostResume()
- # screen rotated
- D/F: onPause()
- D/A: onPause()
- D/F: onStop()
- D/A: onStop()
- D/F: onSaveInstanceState() : outState = [Bundle[{}]]
- D/A: onSaveInstanceState() : outState = [some states from the framework]
- D/F: onDestroyView()
- D/F: onDestroy()
- D/F: onDetach()
- D/A: onDestroy()
- D/A: Activity.constructor()
- D/F: Fragment.constructor()
- D/F: onAttach()
- D/A: onAttachFragment() : fragment = [fragment just created]
- D/F: onCreate() : savedInstanceState = [some states from the framework]
- D/A: onCreate() : savedInstanceState = [some states from the framework]
- D/A: onCreateView() ## multiple calls for different non-fragment parts
- D/A: onContentChanged()
- D/F: onCreateView() : savedInstanceState = [some states from the framework]
- D/A: onCreateView() ## multiple, to setup the view for the fragment
- D/F: onViewCreated() : savedInstanceState = [some states from the framework]
- D/F: onActivityCreated() : savedInstanceState = [some states from the framework]
- D/F: onViewStateRestored() : savedInstanceState = [some states from the framework]
- D/F: onStart()
- D/A: onStart()
- D/A: onRestoreInstanceState() : savedInstanceState = [some states from the framework]
- D/A: onPostCreate() : savedInstanceState = [some states from the framework]
- D/A: onStateNotSaved()
- D/A: onResume()
- D/F: onResume()
- D/A: onResumeFragments()
- D/A: onPostResume()
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement