Class Fragment
- All Implemented Interfaces:
LifecycleOwner
,ViewModelStoreOwner
,View.OnCreateContextMenuListener
- Direct Known Subclasses:
TestFragment
,TestFragment.FragmentA
,TestFragment.FragmentB
FragmentManager
, which can be obtained via
getParentFragmentManager()
and
FragmentController.getFragmentManager()
.
For more information about using fragments, read the Android Fragments developer guide.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
dump
(String prefix, FileDescriptor fd, PrintWriter writer, String... args) Print the Fragment's state into the given stream.final boolean
Subclasses can not override equals().boolean
Returns whether the exit transition and enter transition overlap or not.boolean
Returns whether the return transition and reenter transition overlap or not.final DataSet
Return the arguments supplied when the fragment was instantiated, if any.final FragmentManager
Return a private FragmentManager for placing and managing Fragments inside this Fragment.Return theContext
this fragment is currently associated with.Returns the defaultViewModelProvider.Factory
that should be used when no customFactory
is provided to theViewModelProvider
constructors, such asViewModelProvider(ViewModelStoreOwner)
.Returns the Transition that will be used to move Views into the initial scene.Returns the Transition that will be used to move Views out of the scene when the fragment is removed, hidden, or detached when not popping the back stack.final Object
getHost()
Return the host object of this fragment.final int
getId()
Return the identifier this fragment is known by.Returns the Lifecycle of the provider.final Fragment
Returns the parent Fragment containing this Fragment.final FragmentManager
Return the FragmentManager for interacting with fragments associated with this fragment's activity.Returns the Transition that will be used to move Views in to the scene when returning due to popping a back stack.Returns the Transition that will be used to move Views out of the scene when the Fragment is preparing to be removed, hidden, or detached because of popping the back stack.Returns the Transition that will be used for shared elements transferred into the content Scene.Return the Transition that will be used for shared elements transferred back during a pop of the back stack.final String
getTag()
Get the tag name of the fragment, if specified.getView()
Get the root view for the fragment's layout (the one returned byonCreateView(icyllis.modernui.view.LayoutInflater, icyllis.modernui.view.ViewGroup, icyllis.modernui.util.DataSet)
), if provided.Get aLifecycleOwner
that represents theFragment's View
lifecycle.Retrieve aLiveData
which allows you to observe thelifecycle of the Fragment's View
.Returns theViewModelStore
associated with this Fragmentfinal int
hashCode()
Subclasses can not override hashCode().final boolean
isAdded()
Return true if the fragment is currently added to its activity.final boolean
Return true if the fragment has been explicitly detached from the UI.final boolean
isHidden()
Return true if the fragment has been hidden.final boolean
Return true if the layout is included as part of an activity view hierarchy via the <fragment> tag.final boolean
Return true if this fragment is currently being removed from its activity.final boolean
Return true if the fragment is in the resumed state.final boolean
Returns true if this fragment is added and its state has already been saved by its host.final boolean
Return true if the fragment is currently visible to the user.void
Called when a fragment is first attached to its context.void
Called to do initial creation of a fragment.onCreateAnimator
(int transit, boolean enter, int nextAnim) Called when a fragment loads an animator.void
onCreateContextMenu
(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) Called when a context menu for theview
is about to be shown.onCreateView
(LayoutInflater inflater, ViewGroup container, DataSet savedInstanceState) Called to have the fragment instantiate its user interface view.void
Called when the fragment is no longer in use.void
Called when the view previously created byonCreateView(icyllis.modernui.view.LayoutInflater, icyllis.modernui.view.ViewGroup, icyllis.modernui.util.DataSet)
has been detached from the fragment.void
onDetach()
Called when the fragment is no longer attached to its activity.void
onHiddenChanged
(boolean hidden) Called when the hidden state (as returned byisHidden()
of the fragment has changed.void
onPause()
Called when the Fragment is no longer resumed.void
onPrimaryNavigationFragmentChanged
(boolean isPrimaryNavigationFragment) Callback for when the primary navigation state of this Fragment has changed.void
onResume()
Called when the fragment is visible to the user and actively running.void
onSaveInstanceState
(DataSet outState) Called to ask the fragment to save its current dynamic state, so it can later be reconstructed in a new instance if its process is restarted.void
onStart()
Called when the Fragment is visible to the user.void
onStop()
Called when the Fragment is no longer started.void
onViewCreated
(View view, DataSet savedInstanceState) Called immediately afteronCreateView(LayoutInflater, ViewGroup, DataSet)
has returned, but before any saved state has been restored in to the view.void
onViewStateRestored
(DataSet savedInstanceState) Called when all saved state has been restored into the view hierarchy of the fragment.void
Postpone the entering Fragment transition untilstartPostponedEnterTransition()
orFragmentManager.executePendingTransactions()
has been called.final void
postponeEnterTransition
(long duration, TimeUnit timeUnit) Postpone the entering Fragment transition for a given amount of time and then callstartPostponedEnterTransition()
.void
registerForContextMenu
(View view) Registers a context menu to be shown for the given view (multiple views can show the context menu).final DataSet
Return the arguments supplied when the fragment was instantiated.final Context
Return theContext
this fragment is currently associated with.final Object
Return the host object of this fragment.final Fragment
Returns the parent Fragment containing this Fragment.final View
Get the root view for the fragment's layout (the one returned byonCreateView(icyllis.modernui.view.LayoutInflater, icyllis.modernui.view.ViewGroup, icyllis.modernui.util.DataSet)
).void
setAllowEnterTransitionOverlap
(boolean allow) Sets whether the exit transition and enter transition overlap or not.void
setAllowReturnTransitionOverlap
(boolean allow) Sets whether the return transition and reenter transition overlap or not.void
setArguments
(DataSet args) Supply the construction arguments for this fragment.void
When custom transitions are used with Fragments, the enter transition callback is called when this Fragment is attached or detached when not popping the back stack.void
setEnterTransition
(Transition transition) Sets the Transition that will be used to move Views into the initial scene.void
When custom transitions are used with Fragments, the exit transition callback is called when this Fragment is attached or detached when popping the back stack.void
setExitTransition
(Transition transition) Sets the Transition that will be used to move Views out of the scene when the fragment is removed, hidden, or detached when not popping the back stack.void
setHasOptionsMenu
(boolean hasMenu) Report that this fragment would like to participate in populating the options menu by receiving a call toinvalid reference
#onCreateOptionsMenu
void
setInitialSavedState
(DataSet state) Set the initial saved state that this Fragment should restore itself from when first being constructed, as returned byinvalid reference
FragmentManager.saveFragmentInstanceState
void
setMenuVisibility
(boolean menuVisible) Set a hint for whether this fragment's menu should be visible.void
setReenterTransition
(Transition transition) Sets the Transition that will be used to move Views in to the scene when returning due to popping a back stack.void
setReturnTransition
(Transition transition) Sets the Transition that will be used to move Views out of the scene when the Fragment is preparing to be removed, hidden, or detached because of popping the back stack.void
setSharedElementEnterTransition
(Transition transition) Sets the Transition that will be used for shared elements transferred into the content Scene.void
setSharedElementReturnTransition
(Transition transition) Sets the Transition that will be used for shared elements transferred back during a pop of the back stack.void
Begin postponed transitions afterpostponeEnterTransition()
was called.toString()
void
unregisterForContextMenu
(View view) Prevents a context menu to be shown for the given view.
-
Constructor Details
-
Fragment
public Fragment()Constructor used by the defaultFragmentFactory
. You mustset a custom FragmentFactory
if you want to use a non-default constructor to ensure that your constructor is called when the fragment is re-instantiated.It is strongly recommended to supply arguments with
setArguments(icyllis.modernui.util.DataSet)
and later retrieved by the Fragment withgetArguments()
. These arguments are automatically saved and restored alongside the Fragment.Applications should generally not implement a constructor. Prefer
onAttach(Context)
instead. It is the first place application code can run where the fragment is ready to be used - the point where the fragment is actually associated with its context.
-
-
Method Details
-
getLifecycle
Returns the Lifecycle of the provider.Overriding this method is no longer supported and this method will be made
final
in a future version of Fragment.- Specified by:
getLifecycle
in interfaceLifecycleOwner
- Returns:
- The lifecycle of the provider.
-
getViewLifecycleOwner
Get aLifecycleOwner
that represents theFragment's View
lifecycle. In most cases, this mirrors the lifecycle of the Fragment itself, but in cases ofdetached
Fragments, the lifecycle of the Fragment can be considerably longer than the lifecycle of the View itself.Namely, the lifecycle of the Fragment's View is:
created
afteronViewStateRestored(DataSet)
started
afteronStart()
resumed
afteronResume()
paused
beforeonPause()
stopped
beforeonStop()
destroyed
beforeonDestroyView()
The first method where it is safe to access the view lifecycle is
onCreateView(LayoutInflater, ViewGroup, DataSet)
under the condition that you must return a non-null view (an IllegalStateException will be thrown if you access the view lifecycle but don't return a non-null view).The view lifecycle remains valid through the call to
onDestroyView()
, after whichgetView()
will return null, the view lifecycle will be destroyed, and this method will throw an IllegalStateException. Consider usinggetViewLifecycleOwnerLiveData()
orFragmentTransaction.runOnCommit(Runnable)
to receive a callback for when the Fragment's view lifecycle is available.This should only be called on the main thread.
Overriding this method is no longer supported and this method will be made
final
in a future version of Fragment.- Returns:
- A
LifecycleOwner
that represents theFragment's View
lifecycle. - Throws:
IllegalStateException
- if theFragment's View is null
.
-
getViewLifecycleOwnerLiveData
Retrieve aLiveData
which allows you to observe thelifecycle of the Fragment's View
.This will be set to the new
LifecycleOwner
afteronCreateView(icyllis.modernui.view.LayoutInflater, icyllis.modernui.view.ViewGroup, icyllis.modernui.util.DataSet)
returns a non-null View and will set to null afteronDestroyView()
.Overriding this method is no longer supported and this method will be made
final
in a future version of Fragment.- Returns:
- A LiveData that changes in sync with
getViewLifecycleOwner()
.
-
getViewModelStore
Returns theViewModelStore
associated with this FragmentOverriding this method is no longer supported and this method will be made
final
in a future version of Fragment.- Specified by:
getViewModelStore
in interfaceViewModelStoreOwner
- Returns:
- a
ViewModelStore
- Throws:
IllegalStateException
- if called before the Fragment is attached i.e., before onAttach().
-
getDefaultViewModelProviderFactory
Returns the defaultViewModelProvider.Factory
that should be used when no customFactory
is provided to theViewModelProvider
constructors, such asViewModelProvider(ViewModelStoreOwner)
.The
Fragment's arguments
when this is first called will be used as the defaults to anyinvalid reference
SavedStateHandle
- Specified by:
getDefaultViewModelProviderFactory
in interfaceViewModelStoreOwner
- Returns:
- a
ViewModelProvider.Factory
-
equals
Subclasses can not override equals(). -
hashCode
public final int hashCode()Subclasses can not override hashCode(). -
toString
-
getId
public final int getId()Return the identifier this fragment is known by. This is either the android:id value supplied in a layout or the container view ID supplied when adding the fragment. -
getTag
Get the tag name of the fragment, if specified. -
setArguments
Supply the construction arguments for this fragment. The arguments supplied here will be retained across fragment destroy and creation.This method cannot be called if the fragment is added to a FragmentManager and if
isStateSaved()
would return true. -
getArguments
Return the arguments supplied when the fragment was instantiated, if any. -
requireArguments
Return the arguments supplied when the fragment was instantiated.- Throws:
IllegalStateException
- if no arguments were supplied to the Fragment.- See Also:
-
isStateSaved
public final boolean isStateSaved()Returns true if this fragment is added and its state has already been saved by its host. Any operations that would change saved state should not be performed if this method returns true, and some operations such assetArguments(DataSet)
will fail.- Returns:
- true if this fragment's state has already been saved by its host
-
setInitialSavedState
Set the initial saved state that this Fragment should restore itself from when first being constructed, as returned byinvalid reference
FragmentManager.saveFragmentInstanceState
- Parameters:
state
- The state the fragment should be restored from.
-
getContext
Return theContext
this fragment is currently associated with.- See Also:
-
requireContext
Return theContext
this fragment is currently associated with.- Throws:
IllegalStateException
- if not currently associated with a context.- See Also:
-
getHost
Return the host object of this fragment. May returnnull
if the fragment isn't currently being hosted.- See Also:
-
requireHost
Return the host object of this fragment.- Throws:
IllegalStateException
- if not currently associated with a host.- See Also:
-
getParentFragmentManager
Return the FragmentManager for interacting with fragments associated with this fragment's activity.If this Fragment is a child of another Fragment, the FragmentManager returned here will be the parent's
getChildFragmentManager()
.- Throws:
IllegalStateException
- if not associated with a transaction or host.
-
getChildFragmentManager
Return a private FragmentManager for placing and managing Fragments inside this Fragment. -
getParentFragment
Returns the parent Fragment containing this Fragment. If this Fragment is attached directly to an Activity, returns null. -
requireParentFragment
Returns the parent Fragment containing this Fragment.- Throws:
IllegalStateException
- if this Fragment is attached directly to an Activity or other Fragment host.- See Also:
-
isAdded
public final boolean isAdded()Return true if the fragment is currently added to its activity. -
isDetached
public final boolean isDetached()Return true if the fragment has been explicitly detached from the UI. That is,FragmentTransaction.detach(Fragment)
has been used on it. -
isRemoving
public final boolean isRemoving()Return true if this fragment is currently being removed from its activity. This is not whether its activity is finishing, but rather whether it is in the process of being removed from its activity. -
isInLayout
public final boolean isInLayout()Return true if the layout is included as part of an activity view hierarchy via the <fragment> tag. This will always be true when fragments are created through the <fragment> tag, except in the case where an old fragment is restored from a previous state and it does not appear in the layout of the current state. -
isResumed
public final boolean isResumed()Return true if the fragment is in the resumed state. This is true for the duration ofonResume()
andonPause()
as well. -
isVisible
public final boolean isVisible()Return true if the fragment is currently visible to the user. This means it: (1) has been added, (2) has its view attached to the window, and (3) is not hidden. -
isHidden
public final boolean isHidden()Return true if the fragment has been hidden. By default, fragments are shown. You can find out about changes to this state withonHiddenChanged(boolean)
. Note that the hidden state is orthogonal to other states -- that is, to be visible to the user, a fragment must be both started and not hidden. -
onHiddenChanged
Called when the hidden state (as returned byisHidden()
of the fragment has changed. Fragments start out not hidden; this will be called whenever the fragment changes state from that.- Parameters:
hidden
- True if the fragment is now hidden, false otherwise.
-
setHasOptionsMenu
public void setHasOptionsMenu(boolean hasMenu) Report that this fragment would like to participate in populating the options menu by receiving a call toinvalid reference
#onCreateOptionsMenu
- Parameters:
hasMenu
- If true, the fragment has menu items to contribute.
-
setMenuVisibility
public void setMenuVisibility(boolean menuVisible) Set a hint for whether this fragment's menu should be visible. This is useful if you know that a fragment has been placed in your view hierarchy so that the user can not currently seen it, so any menu items it has should also not be shown.- Parameters:
menuVisible
- The default is true, meaning the fragment's menu will be shown as usual. If false, the user will not see the menu.
-
onAttach
Called when a fragment is first attached to its context.onCreate(DataSet)
will be called after this. -
onCreateAnimator
Called when a fragment loads an animator.- Parameters:
transit
- The value set inFragmentTransaction.setTransition(int)
or 0 if not set.enter
-true
when the fragment is added/attached/shown orfalse
when the fragment is removed/detached/hidden.nextAnim
- The resource set inFragmentTransaction.setCustomAnimations(int, int)
,FragmentTransaction.setCustomAnimations(int, int, int, int)
, or 0 if neither was called. The value will depend on the current operation.
-
onCreate
Called to do initial creation of a fragment. This is called afteronAttach(Context)
and beforeonCreateView(LayoutInflater, ViewGroup, DataSet)
.Note that this can be called while the fragment's activity is still in the process of being created. As such, you can not rely on things like the activity's content view hierarchy being initialized at this point. If you want to do work once the activity itself is created, add a
LifecycleObserver
on the activity's Lifecycle, removing it when it receives theLifecycle.State.CREATED
callback.Any restored child fragments will be created before the base
Fragment.onCreate
method returns.- Parameters:
savedInstanceState
- If the fragment is being re-created from a previous saved state, this is the state.
-
onCreateView
@UiThread @Nullable public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable DataSet savedInstanceState) Called to have the fragment instantiate its user interface view. This is optional, and non-graphical fragments can return null. This will be called betweenonCreate(DataSet)
andonViewCreated(View, DataSet)
.It is recommended to only inflate the layout in this method and move logic that operates on the returned View to
onViewCreated(View, DataSet)
.If you return a View from here, you will later be called in
onDestroyView()
when the view is being released.- Parameters:
inflater
- The LayoutInflater object that can be used to inflate any views in the fragmentcontainer
- If non-null, this is the parent view that the fragment's UI should be attached to. The fragment should not add the view itself, but this can be used to generate the LayoutParams of the view.savedInstanceState
- If non-null, this fragment is being re-constructed from a previous saved state as given here.- Returns:
- Return the View for the fragment's UI, or null.
-
onViewCreated
Called immediately afteronCreateView(LayoutInflater, ViewGroup, DataSet)
has returned, but before any saved state has been restored in to the view. This gives subclasses a chance to initialize themselves once they know their view hierarchy has been completely created. The fragment's view hierarchy is not however attached to its parent at this point.- Parameters:
view
- The View returned byonCreateView(LayoutInflater, ViewGroup, DataSet)
.savedInstanceState
- If non-null, this fragment is being re-constructed from a previous saved state as given here.
-
getView
Get the root view for the fragment's layout (the one returned byonCreateView(icyllis.modernui.view.LayoutInflater, icyllis.modernui.view.ViewGroup, icyllis.modernui.util.DataSet)
), if provided.- Returns:
- The fragment's root view, or null if it has no layout.
-
requireView
Get the root view for the fragment's layout (the one returned byonCreateView(icyllis.modernui.view.LayoutInflater, icyllis.modernui.view.ViewGroup, icyllis.modernui.util.DataSet)
).- Throws:
IllegalStateException
- if no view was returned byonCreateView(icyllis.modernui.view.LayoutInflater, icyllis.modernui.view.ViewGroup, icyllis.modernui.util.DataSet)
.- See Also:
-
onViewStateRestored
Called when all saved state has been restored into the view hierarchy of the fragment. This can be used to do initialization based on saved state that you are letting the view hierarchy track itself, such as whether check box widgets are currently checked. This is called afteronViewCreated(View, DataSet)
and beforeonStart()
.- Parameters:
savedInstanceState
- If the fragment is being re-created from a previous saved state, this is the state.
-
onStart
Called when the Fragment is visible to the user. -
onResume
Called when the fragment is visible to the user and actively running. -
onSaveInstanceState
Called to ask the fragment to save its current dynamic state, so it can later be reconstructed in a new instance if its process is restarted. If a new instance of the fragment later needs to be created, the data you place in the Bundle here will be available in the Bundle given toonCreate(DataSet)
,onCreateView(LayoutInflater, ViewGroup, DataSet)
, andonViewCreated(View, DataSet)
.Note however: this method may be called at any time before
onDestroy()
. There are many situations where a fragment may be mostly torn down (such as when placed on the back stack with no UI showing), but its state will not be saved until its owning activity actually needs to save its state.- Parameters:
outState
- Bundle in which to place your saved state.
-
onPause
Called when the Fragment is no longer resumed. -
onStop
Called when the Fragment is no longer started. -
onDestroyView
Called when the view previously created byonCreateView(icyllis.modernui.view.LayoutInflater, icyllis.modernui.view.ViewGroup, icyllis.modernui.util.DataSet)
has been detached from the fragment. The next time the fragment needs to be displayed, a new view will be created. This is called afteronStop()
and beforeonDestroy()
. It is called regardless of whetheronCreateView(icyllis.modernui.view.LayoutInflater, icyllis.modernui.view.ViewGroup, icyllis.modernui.util.DataSet)
returned a non-null view. Internally it is called after the view's state has been saved, but before it has been removed from its parent. -
onDestroy
Called when the fragment is no longer in use. This is called afteronStop()
and beforeonDetach()
. -
onDetach
Called when the fragment is no longer attached to its activity. This is called afteronDestroy()
. -
onCreateContextMenu
@UiThread public void onCreateContextMenu(@NonNull ContextMenu menu, @NonNull View v, @Nullable ContextMenu.ContextMenuInfo menuInfo) Called when a context menu for theview
is about to be shown. Unlikeinvalid reference
#onCreateOptionsMenu
AdapterView
subclasses, this can be found in themenuInfo
)).Use
invalid reference
#onContextItemSelected(MenuItem)
It is not safe to hold onto the context menu after this method returns. Called when the context menu for this view is being built. It is not safe to hold onto the menu after this method returns.
- Specified by:
onCreateContextMenu
in interfaceView.OnCreateContextMenuListener
- Parameters:
menu
- The context menu that is being builtv
- The view for which the context menu is being builtmenuInfo
- Extra information about the item for which the context menu should be shown. This information will vary depending on the class of v.
-
registerForContextMenu
Registers a context menu to be shown for the given view (multiple views can show the context menu). This method will set theView.OnCreateContextMenuListener
on the view to this fragment, soonCreateContextMenu(ContextMenu, View, ContextMenuInfo)
will be called when it is time to show the context menu.- Parameters:
view
- The view that should show a context menu.- See Also:
-
unregisterForContextMenu
Prevents a context menu to be shown for the given view. This method will remove theView.OnCreateContextMenuListener
on the view.- Parameters:
view
- The view that should stop showing a context menu.- See Also:
-
setEnterTransition
Sets the Transition that will be used to move Views into the initial scene. The entering Views will be those that are regular Views or ViewGroups that haveViewGroup.isTransitionGroup()
return true. Typical Transitions will extendVisibility
as entering is governed by changing visibility fromView.INVISIBLE
toView.VISIBLE
. Iftransition
is null, entering Views will remain unaffected.- Parameters:
transition
- The Transition to use to move Views into the initial Scene.
-
getEnterTransition
Returns the Transition that will be used to move Views into the initial scene. The entering Views will be those that are regular Views or ViewGroups that haveViewGroup.isTransitionGroup()
return true. Typical Transitions will extendVisibility
as entering is governed by changing visibility fromView.INVISIBLE
toView.VISIBLE
.- Returns:
- the Transition to use to move Views into the initial Scene.
-
setReturnTransition
Sets the Transition that will be used to move Views out of the scene when the Fragment is preparing to be removed, hidden, or detached because of popping the back stack. The exiting Views will be those that are regular Views or ViewGroups that haveViewGroup.isTransitionGroup()
return true. Typical Transitions will extendVisibility
as entering is governed by changing visibility fromView.VISIBLE
toView.INVISIBLE
. Iftransition
is null, entering Views will remain unaffected. If nothing is set, the default will be to use the same value as set insetEnterTransition(Transition)
.- Parameters:
transition
- The Transition to use to move Views out of the Scene when the Fragment is preparing to close due to popping the back stack.
-
getReturnTransition
Returns the Transition that will be used to move Views out of the scene when the Fragment is preparing to be removed, hidden, or detached because of popping the back stack. The exiting Views will be those that are regular Views or ViewGroups that haveViewGroup.isTransitionGroup()
return true. Typical Transitions will extendVisibility
as entering is governed by changing visibility fromView.VISIBLE
toView.INVISIBLE
. If nothing is set, the default will be to use the same transition asgetEnterTransition()
.- Returns:
- the Transition to use to move Views out of the Scene when the Fragment is preparing to close due to popping the back stack.
-
setExitTransition
Sets the Transition that will be used to move Views out of the scene when the fragment is removed, hidden, or detached when not popping the back stack. The exiting Views will be those that are regular Views or ViewGroups that haveViewGroup.isTransitionGroup()
return true. Typical Transitions will extendVisibility
as exiting is governed by changing visibility fromView.VISIBLE
toView.INVISIBLE
. If transition is null, the views will remain unaffected.- Parameters:
transition
- The Transition to use to move Views out of the Scene when the Fragment is being closed not due to popping the back stack.
-
getExitTransition
Returns the Transition that will be used to move Views out of the scene when the fragment is removed, hidden, or detached when not popping the back stack. The exiting Views will be those that are regular Views or ViewGroups that haveViewGroup.isTransitionGroup()
return true. Typical Transitions will extendVisibility
as exiting is governed by changing visibility fromView.VISIBLE
toView.INVISIBLE
. If transition is null, the views will remain unaffected.- Returns:
- the Transition to use to move Views out of the Scene when the Fragment is being closed not due to popping the back stack.
-
setReenterTransition
Sets the Transition that will be used to move Views in to the scene when returning due to popping a back stack. The entering Views will be those that are regular Views or ViewGroups that haveViewGroup.isTransitionGroup()
return true. Typical Transitions will extendVisibility
as exiting is governed by changing visibility fromView.VISIBLE
toView.INVISIBLE
. If transition is null, the views will remain unaffected. If nothing is set, the default will be to use the same transition asgetExitTransition()
.- Parameters:
transition
- The Transition to use to move Views into the scene when reentering from a previously-started Activity due to popping the back stack.
-
getReenterTransition
Returns the Transition that will be used to move Views in to the scene when returning due to popping a back stack. The entering Views will be those that are regular Views or ViewGroups that haveViewGroup.isTransitionGroup()
return true. Typical Transitions will extendVisibility
as exiting is governed by changing visibility fromView.VISIBLE
toView.INVISIBLE
. If nothing is set, the default will be to use the same transition asgetExitTransition()
.- Returns:
- the Transition to use to move Views into the scene when reentering from a previously-started Activity due to popping the back stack.
-
setAllowEnterTransitionOverlap
public void setAllowEnterTransitionOverlap(boolean allow) Sets whether the exit transition and enter transition overlap or not. When true, the enter transition will start as soon as possible. When false, the enter transition will wait until the exit transition completes before starting.- Parameters:
allow
- true to start the enter transition when possible or false to wait until the exiting transition completes.
-
getAllowEnterTransitionOverlap
public boolean getAllowEnterTransitionOverlap()Returns whether the exit transition and enter transition overlap or not. When true, the enter transition will start as soon as possible. When false, the enter transition will wait until the exit transition completes before starting.- Returns:
- true when the enter transition should start as soon as possible or false to when it should wait until the exiting transition completes.
-
setAllowReturnTransitionOverlap
public void setAllowReturnTransitionOverlap(boolean allow) Sets whether the return transition and reenter transition overlap or not. When true, the reenter transition will start as soon as possible. When false, the reenter transition will wait until the return transition completes before starting.- Parameters:
allow
- true to start the reenter transition when possible or false to wait until the return transition completes.
-
getAllowReturnTransitionOverlap
public boolean getAllowReturnTransitionOverlap()Returns whether the return transition and reenter transition overlap or not. When true, the reenter transition will start as soon as possible. When false, the reenter transition will wait until the return transition completes before starting.- Returns:
- true to start the reenter transition when possible or false to wait until the return transition completes.
-
postponeEnterTransition
public void postponeEnterTransition()Postpone the entering Fragment transition untilstartPostponedEnterTransition()
orFragmentManager.executePendingTransactions()
has been called.This method gives the Fragment the ability to delay Fragment animations until all data is loaded. Until then, the added, shown, and attached Fragments will be INVISIBLE and removed, hidden, and detached Fragments won't be have their Views removed. The transaction runs when all postponed added Fragments in the transaction have called
startPostponedEnterTransition()
.This method should be called before being added to the FragmentTransaction or in
onCreate(DataSet)
,onAttach(Context)
, oronCreateView(LayoutInflater, ViewGroup, DataSet)
}.startPostponedEnterTransition()
must be called to allow the Fragment to start the transitions.When a FragmentTransaction is started that may affect a postponed FragmentTransaction, based on which containers are in their operations, the postponed FragmentTransaction will have its start triggered. The early triggering may result in faulty or nonexistent animations in the postponed transaction. FragmentTransactions that operate only on independent containers will not interfere with each other's postponement.
Calling postponeEnterTransition on Fragments with a null View will not postpone the transition.
- See Also:
-
postponeEnterTransition
Postpone the entering Fragment transition for a given amount of time and then callstartPostponedEnterTransition()
.This method gives the Fragment the ability to delay Fragment animations for a given amount of time. Until then, the added, shown, and attached Fragments will be INVISIBLE and removed, hidden, and detached Fragments won't be have their Views removed. The transaction runs when all postponed added Fragments in the transaction have called
startPostponedEnterTransition()
.This method should be called before being added to the FragmentTransaction or in
onCreate(DataSet)
,onAttach(Context)
, oronCreateView(LayoutInflater, ViewGroup, DataSet)
}.When a FragmentTransaction is started that may affect a postponed FragmentTransaction, based on which containers are in their operations, the postponed FragmentTransaction will have its start triggered. The early triggering may result in faulty or nonexistent animations in the postponed transaction. FragmentTransactions that operate only on independent containers will not interfere with each other's postponement.
Calling postponeEnterTransition on Fragments with a null View will not postpone the transition.
- Parameters:
duration
- The length of the delay intimeUnit
unitstimeUnit
- The units of time forduration
- See Also:
-
startPostponedEnterTransition
public void startPostponedEnterTransition()Begin postponed transitions afterpostponeEnterTransition()
was called. If postponeEnterTransition() was called, you must call startPostponedEnterTransition() orFragmentManager.executePendingTransactions()
to complete the FragmentTransaction. If postponement was interrupted withFragmentManager.executePendingTransactions()
, beforestartPostponedEnterTransition()
, animations may not run or may execute improperly. -
dump
public void dump(@NonNull String prefix, @Nullable FileDescriptor fd, @NonNull PrintWriter writer, @Nullable String... args) Print the Fragment's state into the given stream.- Parameters:
prefix
- Text to print at the front of each line.fd
- The raw file descriptor that the dump is being sent to.writer
- The PrintWriter to which you should dump your state. This will be closed for you after you return.args
- additional arguments to the dump request.
-