- onAttach()
- onCreate()
- onCreateDialog()
- DialogFragment only
- onCreateView()
- onViewStateRestored()
- onStart()
- onResume()
- onDismiss()
- DialogFragment only
- onPause()
- onSaveInstanceState()
- onStop()
- onDestroyView()
- onDestroy()
- onDetach()
Note that onRestoreInstanceState() does not exist in Fragment(s).
- DialogFragment.dialog.setOnShowListener()
- onConfigurationChanged()
is a container to which multiple fragments can be added.
- is the root of a fragment's layout.
- is created by onCreateView().
- is detached from a fragment by onDestroyView().
- gets fragments that provide a UI in the activity layout.
- gets fragments whether or not they provide a UI in the activity layout.
- Despite the documentation, I have found that findFragmentByTag() can get fragments that are detached and not in the back stack.
- does not include fragments that are detached.
- https://developer.android.com/guide/components/fragments#Managing
- returns a FragmentManager associated with the activity.
- which can place a fragment in
<androidx.fragment.app.FragmentContainerView>
in the activity's layout file.
- which can place a fragment in
- FragmentActivity is namely an Activity.
- returns a FragmentManager associated with the fragment's activity.
- which can place a child fragment in
<androidx.fragment.app.FragmentContainerView>
in the activity's layout file.
- which can place a child fragment in
- returns a private FragmentManager associated with the fragment.
- which can place a child fragment in
<androidx.fragment.app.FragmentContainerView>
in the fragment's layout file.
- which can place a child fragment in
- is NOT a collection of Fragment(s) but a collection of FragmentTransaction(s).
- is managed by the parent activity.
- Fragment = childFragmentManager = fragment back stack = 1 : 1 : 1
- In a Fragment, the following removes all the existing fragments, and then add a FragmentA
fragmentManager.commit {
replace(FragmentA)
}
- When
FragmentManager.popBackStack()
is called, the following happens in sequence.FragmentManager.primaryNavigationFragment.childFragmentManager.popBackStack()
is called.- If the above returns false,
FragmentActivity.supportFragmentManager.popBackStack()
is called. - If the above returns false, the app quits.
- calls
Fragment.onDestroy()
andFragment.onDetach()
ifFragmentTransaction.addToBackStack(...)
is NOT called in the same transaction. - calls up to
Fragment.onDestroyView()
ifFragmentTransaction.addToBackStack(...)
is called in the same transaction.
- adds a FragmentTransaction in the back stack instead of adding an Fragment in the back stack.
- will run the sequence of the operations of the transaction in the reverse order when the Up or Back button is pressed.
- attaches a fragment to the UI.
- calls
Fragment.onCreateView()
.
- detaches a fragment to the UI.
- calls
Fragment.onDestroyView()
.