diff --git a/README.md b/README.md index 3071d2d..b21d752 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,18 @@ this way, you can see how your fragments interact with your activities. If you see any discrepancies or errors in this diagram, please submit a pull request or contact [steve@staticfree.info](mailto:steve@staticfree.info). +## Activity and Fragment Lifecycles + Vector versions suitable for printing: [PDF][] or [SVG][] ![A Complete Android Fragment & Activity Lifecycle](complete_android_fragment_lifecycle.png) +## Activity, Fragment and FragmentManager Lifecycle Integration + +Vector versions suitable for printing [PDF2][] or [SVG2][] + +![A Integration Of Fragments into Activities via Fragment Manager](android-lifecycle-activity-to-fragments.png) + ### Some Notes This intentionally leaves off user-triggered callbacks (such as @@ -39,3 +47,5 @@ something out. [PDF]: complete_android_fragment_lifecycle.pdf [SVG]: complete_android_fragment_lifecycle.svg [CC-BY-SA]: https://creativecommons.org/licenses/by-sa/4.0/ +[PDF2]: android-lifecycle-activity-to-fragments.pdf +[SVG2]: android-lifecycle-activity-to-fragments.svg diff --git a/android-lifecycle-activity-to-fragments.pdf b/android-lifecycle-activity-to-fragments.pdf new file mode 100644 index 0000000..70fa47c Binary files /dev/null and b/android-lifecycle-activity-to-fragments.pdf differ diff --git a/android-lifecycle-activity-to-fragments.png b/android-lifecycle-activity-to-fragments.png new file mode 100644 index 0000000..22969f8 Binary files /dev/null and b/android-lifecycle-activity-to-fragments.png differ diff --git a/android-lifecycle-activity-to-fragments.svg b/android-lifecycle-activity-to-fragments.svg new file mode 100644 index 0000000..34fea0b --- /dev/null +++ b/android-lifecycle-activity-to-fragments.svg @@ -0,0 +1,2 @@ + +
onPreparePanel
onPreparePanel
Activity is launched
Activity is launched
onCreate()
onCreate()
onAttachFragment()
onAttachFragment()
onStart()
onStart()
onContentChanged()
onContentChanged()
onRestart()
onRestart()
onRestoreInstanceState()
onRestoreInstanceState()
onPostCreate()
onPostCreate()
onActivityResult()
onActivityResult()
Called when an activity 
you launched exits
[Not supported by viewer]
onResume()
onResume()
onPostResume()
onPostResume()
onAttachedToWindow()
onAttachedToWindow()
onCreateOptionsMenu()
onCreateOptionsMenu()
Activity is running
Activity is running
onPrepareOptionsMenu()
onPrepareOptionsMenu()
onUserInteraction()
onUserInteraction()
onUserLeaveHint()
onUserLeaveHint()
onPause()
onPause()
onSaveInstanceState()
onSaveInstanceState()
onStop()
onStop()
onDestroy()
onDestroy()
Activity is shutdown
Activity is shutdown
Only called when 
onUserInteraction() 
is called first.
[Not supported by viewer]
Called when user 
interact with activity.
[Not supported by viewer]
User navigates to activity
User navigates to activity
User returns 
to the activity
[Not supported by viewer]
FragmentManager
FragmentManager
dispatchCreate()
dispatchCreate()
dispatchStart()
dispatchStart()
dispatchResume()
[Not supported by viewer]
dispatchPause()
[Not supported by viewer]
dispatchStop()
[Not supported by viewer]
dispatchDestroy()
[Not supported by viewer]
onResumeFragment()
onResumeFragment()
dispatchActivityCreated()
dispatchActivityCreated()
saveAllStates()
saveAllStates()
Fragment is added to existing activity
Fragment is added to existing activity
Fragment is inflated from layout
Fragment is inflated from layout
onInflate()
onInflate()
onAttach()
onAttach()
onCreate()
onCreate()
onCreateView()
onCreateView()
onViewCreated()
onViewCreated()
onActivityCreated()
onActivityCreated()
onViewStateRestored()
onViewStateRestored()
onStart()
onStart()
onResume()
onResume()
onCreateOptionsMenu()
onCreateOptionsMenu()
onPrepareOptionsMenu()
onPrepareOptionsMenu()
Fragment is active
Fragment is active
onPause()
onPause()
onSaveInstanceState()
onSaveInstanceState()
onStop()
onStop()
onDestroyView()
onDestroyView()
onDestroy()
onDestroy()
onDetach()
onDetach()
Fragment is destroyed
Fragment is destroyed
☑ retainInstance
<span>☑&nbsp;</span>retainInstance
App process killed
App process killed
INITIALIZING
INITIALIZING
CREATED
CREATED
<fragment reference sent>
&lt;fragment reference sent&gt;
☑ retainInstance
<span>☑&nbsp;</span>retainInstance
ACTIVITY_CREATED
ACTIVITY_CREATED
INITIALIZING --> CREATED: performCreate()
INITIALIZING --&gt; CREATED: performCreate()
CREATED --> ACTIVITY_CREATED: performActivityCreated()
CREATED --&gt; ACTIVITY_CREATED: performActivityCreated()
STARTED
STARTED
ACTIVITY_CREATED | STOPPED --> STARTED: performStarted()
ACTIVITY_CREATED | STOPPED --&gt; STARTED: performStarted()
STARTED --> RESUMED: performResume()
STARTED --&gt; RESUMED: performResume()
RESUMED
[Not supported by viewer]
RESUMED --> STARTED: performPause()
RESUMED --&gt; STARTED: performPause()
STARTED
STARTED
STOPPED
STOPPED
STARTED --> STOPPED: performStop()
STARTED --&gt; STOPPED: performStop()
ACTIVITY_CREATED --> CREATED: performDestroyView()
ACTIVITY_CREATED --&gt; CREATED: performDestroyView()
INITIALIZING
INITIALIZING
onRetainNonConfigurationInstance()
onRetainNonConfigurationInstance()
dispatchReallyStop()
[Not supported by viewer]
ACTIVITY_CREATED
ACTIVITY_CREATED
STOPPED --> ACTIVITY_CREATED: performReallyStop()
STOPPED --&gt; ACTIVITY_CREATED: performReallyStop()
CREATED --> *
CREATED --&gt; *
CREATED --> INITIALIZING: performDestroy()
CREATED --&gt; INITIALIZING: performDestroy()
dispatchCreateOptionsMenu()
dispatchCreateOptionsMenu()
dispatchPrepareOptionsMenu()
dispatchPrepareOptionsMenu()
dispatchActivityCreated() called only
one time in the lifecycle, on first loop
[Not supported by viewer]
ACTIVITY
android.support.v4.app.FragmentActivity
ACTIVITY<div>android.support.v4.app.FragmentActivity</div>
FRAGMENT
android.support.v4.app.Fragment
FRAGMENT<div>android.support.v4.app.Fragment</div>
FRAGMENT MANAGER
android.support.v4.app.FragmentManager
FRAGMENT MANAGER<div>android.support.v4.app.FragmentManager</div>
Common
Common
Uncommon
Uncommon
Conditional
Conditional
STATE MACHINE, STATE
STATE MACHINE, STATE
Legend, v1.0.0
Legend, v1.0.0
Scope of Execution
Scope of Execution
\ No newline at end of file diff --git a/complete_android_fragment_lifecycle.png b/complete_android_fragment_lifecycle.png index 259990e..90796c1 100644 Binary files a/complete_android_fragment_lifecycle.png and b/complete_android_fragment_lifecycle.png differ