Class Fragment

java.lang.Object
icyllis.modernui.fragment.Fragment
All Implemented Interfaces:
LifecycleOwner, ViewModelStoreOwner, View.OnCreateContextMenuListener
Direct Known Subclasses:
TestFragment, TestFragment.FragmentA, TestFragment.FragmentB

A Fragment is a piece of an application's user interface or behavior that can be placed in a host object. Interaction with fragments is done through FragmentManager, which can be obtained via getParentFragmentManager() and FragmentController.getFragmentManager().

For more information about using fragments, read the Android Fragments developer guide.

  • Constructor Details

    • Fragment

      public Fragment()
      Constructor used by the default FragmentFactory. You must set 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 with getArguments(). 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

      @NonNull public Lifecycle 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 interface LifecycleOwner
      Returns:
      The lifecycle of the provider.
    • getViewLifecycleOwner

      @UiThread @NonNull public LifecycleOwner getViewLifecycleOwner()
      Get a LifecycleOwner that represents the Fragment's View lifecycle. In most cases, this mirrors the lifecycle of the Fragment itself, but in cases of detached 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:

      1. created after onViewStateRestored(DataSet)
      2. started after onStart()
      3. resumed after onResume()
      4. paused before onPause()
      5. stopped before onStop()
      6. destroyed before onDestroyView()

      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 which getView() will return null, the view lifecycle will be destroyed, and this method will throw an IllegalStateException. Consider using getViewLifecycleOwnerLiveData() or FragmentTransaction.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 the Fragment's View lifecycle.
      Throws:
      IllegalStateException - if the Fragment's View is null.
    • getViewLifecycleOwnerLiveData

      @NonNull public LiveData<LifecycleOwner> getViewLifecycleOwnerLiveData()
      Retrieve a LiveData which allows you to observe the lifecycle of the Fragment's View.

      This will be set to the new LifecycleOwner after onCreateView(icyllis.modernui.view.LayoutInflater, icyllis.modernui.view.ViewGroup, icyllis.modernui.util.DataSet) returns a non-null View and will set to null after onDestroyView().

      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

      @NonNull public ViewModelStore getViewModelStore()
      Returns the ViewModelStore associated with this Fragment

      Overriding this method is no longer supported and this method will be made final in a future version of Fragment.

      Specified by:
      getViewModelStore in interface ViewModelStoreOwner
      Returns:
      a ViewModelStore
      Throws:
      IllegalStateException - if called before the Fragment is attached i.e., before onAttach().
    • getDefaultViewModelProviderFactory

      public ViewModelProvider.Factory getDefaultViewModelProviderFactory()
      Returns the default ViewModelProvider.Factory that should be used when no custom Factory is provided to the ViewModelProvider constructors, such as ViewModelProvider(ViewModelStoreOwner).

      The Fragment's arguments when this is first called will be used as the defaults to any

      invalid reference
      SavedStateHandle
      passed to a view model created using this factory.

      Specified by:
      getDefaultViewModelProviderFactory in interface ViewModelStoreOwner
      Returns:
      a ViewModelProvider.Factory
    • equals

      public final boolean equals(@Nullable Object o)
      Subclasses can not override equals().
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Subclasses can not override hashCode().
      Overrides:
      hashCode in class Object
    • toString

      @NonNull public String toString()
      Overrides:
      toString in class Object
    • 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

      @Nullable public final String getTag()
      Get the tag name of the fragment, if specified.
    • setArguments

      public void setArguments(@Nullable DataSet args)
      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

      @Nullable public final DataSet getArguments()
      Return the arguments supplied when the fragment was instantiated, if any.
    • requireArguments

      @NonNull public final DataSet 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 as setArguments(DataSet) will fail.
      Returns:
      true if this fragment's state has already been saved by its host
    • setInitialSavedState

      public void setInitialSavedState(@Nullable DataSet state)
      Set the initial saved state that this Fragment should restore itself from when first being constructed, as returned by
      invalid reference
      FragmentManager.saveFragmentInstanceState
      .
      Parameters:
      state - The state the fragment should be restored from.
    • getContext

      @Nullable public Context getContext()
      Return the Context this fragment is currently associated with.
      See Also:
    • requireContext

      @NonNull public final Context requireContext()
      Return the Context this fragment is currently associated with.
      Throws:
      IllegalStateException - if not currently associated with a context.
      See Also:
    • getHost

      @Nullable public final Object getHost()
      Return the host object of this fragment. May return null if the fragment isn't currently being hosted.
      See Also:
    • requireHost

      @NonNull public final Object requireHost()
      Return the host object of this fragment.
      Throws:
      IllegalStateException - if not currently associated with a host.
      See Also:
    • getParentFragmentManager

      @NonNull public final FragmentManager 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

      @NonNull public final FragmentManager getChildFragmentManager()
      Return a private FragmentManager for placing and managing Fragments inside this Fragment.
    • getParentFragment

      @Nullable public final Fragment getParentFragment()
      Returns the parent Fragment containing this Fragment. If this Fragment is attached directly to an Activity, returns null.
    • requireParentFragment

      @NonNull public final Fragment 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 of onResume() and onPause() 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 with onHiddenChanged(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

      @UiThread public void onHiddenChanged(boolean hidden)
      Called when the hidden state (as returned by isHidden() 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 to
      invalid reference
      #onCreateOptionsMenu
      and related methods.
      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

      @UiThread @CallSuper public void onAttach(@NonNull Context context)
      Called when a fragment is first attached to its context. onCreate(DataSet) will be called after this.
    • onCreateAnimator

      @UiThread @Nullable public Animator onCreateAnimator(int transit, boolean enter, int nextAnim)
      Called when a fragment loads an animator.
      Parameters:
      transit - The value set in FragmentTransaction.setTransition(int) or 0 if not set.
      enter - true when the fragment is added/attached/shown or false when the fragment is removed/detached/hidden.
      nextAnim - The resource set in FragmentTransaction.setCustomAnimations(int, int), FragmentTransaction.setCustomAnimations(int, int, int, int), or 0 if neither was called. The value will depend on the current operation.
    • onCreate

      @UiThread @CallSuper public void onCreate(@Nullable DataSet savedInstanceState)
      Called to do initial creation of a fragment. This is called after onAttach(Context) and before onCreateView(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 the Lifecycle.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 between onCreate(DataSet) and onViewCreated(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 fragment
      container - 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

      @UiThread public void onViewCreated(@NonNull View view, @Nullable DataSet savedInstanceState)
      Called immediately after onCreateView(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 by onCreateView(LayoutInflater, ViewGroup, DataSet).
      savedInstanceState - If non-null, this fragment is being re-constructed from a previous saved state as given here.
    • getView

      @Nullable public View getView()
      Get the root view for the fragment's layout (the one returned by onCreateView(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

      @NonNull public final View requireView()
      Throws:
      IllegalStateException - if no view was returned by onCreateView(icyllis.modernui.view.LayoutInflater, icyllis.modernui.view.ViewGroup, icyllis.modernui.util.DataSet).
      See Also:
    • onViewStateRestored

      @UiThread @CallSuper public void onViewStateRestored(@Nullable DataSet savedInstanceState)
      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 after onViewCreated(View, DataSet) and before onStart().
      Parameters:
      savedInstanceState - If the fragment is being re-created from a previous saved state, this is the state.
    • onStart

      @UiThread @CallSuper public void onStart()
      Called when the Fragment is visible to the user.
    • onResume

      @UiThread @CallSuper public void onResume()
      Called when the fragment is visible to the user and actively running.
    • onSaveInstanceState

      @UiThread public void onSaveInstanceState(@NonNull 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. 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 to onCreate(DataSet), onCreateView(LayoutInflater, ViewGroup, DataSet), and onViewCreated(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.
    • onPrimaryNavigationFragmentChanged

      @UiThread public void onPrimaryNavigationFragmentChanged(boolean isPrimaryNavigationFragment)
      Callback for when the primary navigation state of this Fragment has changed. This can be the result of the getParentFragmentManager() containing FragmentManager} having its primary navigation fragment changed via FragmentTransaction.setPrimaryNavigationFragment(icyllis.modernui.fragment.Fragment) or due to the primary navigation fragment changing in a parent FragmentManager.
      Parameters:
      isPrimaryNavigationFragment - True if and only if this Fragment and any parent fragment is set as the primary navigation fragment via FragmentTransaction.setPrimaryNavigationFragment(icyllis.modernui.fragment.Fragment).
    • onPause

      @UiThread @CallSuper public void onPause()
      Called when the Fragment is no longer resumed.
    • onStop

      @UiThread @CallSuper public void onStop()
      Called when the Fragment is no longer started.
    • onDestroyView

      @UiThread @CallSuper public void onDestroyView()
      Called when the view previously created by onCreateView(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 after onStop() and before onDestroy(). It is called regardless of whether onCreateView(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

      @UiThread @CallSuper public void onDestroy()
      Called when the fragment is no longer in use. This is called after onStop() and before onDetach().
    • onDetach

      @UiThread @CallSuper public void onDetach()
      Called when the fragment is no longer attached to its activity. This is called after onDestroy().
    • onCreateContextMenu

      @UiThread public void onCreateContextMenu(@NonNull ContextMenu menu, @NonNull View v, @Nullable ContextMenu.ContextMenuInfo menuInfo)
      Called when a context menu for the view is about to be shown. Unlike
      invalid reference
      #onCreateOptionsMenu
      , this will be called every time the context menu is about to be shown and should be populated for the view (or item inside the view for AdapterView subclasses, this can be found in the menuInfo)).

      Use

      invalid reference
      #onContextItemSelected(MenuItem)
      to know when an item has been selected.

      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 interface View.OnCreateContextMenuListener
      Parameters:
      menu - The context menu that is being built
      v - The view for which the context menu is being built
      menuInfo - Extra information about the item for which the context menu should be shown. This information will vary depending on the class of v.
    • registerForContextMenu

      public void registerForContextMenu(@NonNull View view)
      Registers a context menu to be shown for the given view (multiple views can show the context menu). This method will set the View.OnCreateContextMenuListener on the view to this fragment, so onCreateContextMenu(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

      public void unregisterForContextMenu(@NonNull View view)
      Prevents a context menu to be shown for the given view. This method will remove the View.OnCreateContextMenuListener on the view.
      Parameters:
      view - The view that should stop showing a context menu.
      See Also:
    • setEnterSharedElementCallback

      public void setEnterSharedElementCallback(@Nullable SharedElementCallback callback)
      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.
      Parameters:
      callback - Used to manipulate the shared element transitions on this Fragment when added not as a pop from the back stack.
    • setExitSharedElementCallback

      public void setExitSharedElementCallback(@Nullable SharedElementCallback callback)
      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.
      Parameters:
      callback - Used to manipulate the shared element transitions on this Fragment when added as a pop from the back stack.
    • setEnterTransition

      public void setEnterTransition(@Nullable Transition transition)
      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 have ViewGroup.isTransitionGroup() return true. Typical Transitions will extend Visibility as entering is governed by changing visibility from View.INVISIBLE to View.VISIBLE. If transition is null, entering Views will remain unaffected.
      Parameters:
      transition - The Transition to use to move Views into the initial Scene.
    • getEnterTransition

      @Nullable public Transition 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 have ViewGroup.isTransitionGroup() return true. Typical Transitions will extend Visibility as entering is governed by changing visibility from View.INVISIBLE to View.VISIBLE.
      Returns:
      the Transition to use to move Views into the initial Scene.
    • setReturnTransition

      public void setReturnTransition(@Nullable 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. The exiting Views will be those that are regular Views or ViewGroups that have ViewGroup.isTransitionGroup() return true. Typical Transitions will extend Visibility as entering is governed by changing visibility from View.VISIBLE to View.INVISIBLE. If transition is null, entering Views will remain unaffected. If nothing is set, the default will be to use the same value as set in setEnterTransition(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

      @Nullable public Transition 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 have ViewGroup.isTransitionGroup() return true. Typical Transitions will extend Visibility as entering is governed by changing visibility from View.VISIBLE to View.INVISIBLE. If nothing is set, the default will be to use the same transition as getEnterTransition().
      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

      public void setExitTransition(@Nullable 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. The exiting Views will be those that are regular Views or ViewGroups that have ViewGroup.isTransitionGroup() return true. Typical Transitions will extend Visibility as exiting is governed by changing visibility from View.VISIBLE to View.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

      @Nullable public Transition 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 have ViewGroup.isTransitionGroup() return true. Typical Transitions will extend Visibility as exiting is governed by changing visibility from View.VISIBLE to View.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

      public void setReenterTransition(@Nullable Transition transition)
      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 have ViewGroup.isTransitionGroup() return true. Typical Transitions will extend Visibility as exiting is governed by changing visibility from View.VISIBLE to View.INVISIBLE. If transition is null, the views will remain unaffected. If nothing is set, the default will be to use the same transition as getExitTransition().
      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

      @Nullable public Transition 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 have ViewGroup.isTransitionGroup() return true. Typical Transitions will extend Visibility as exiting is governed by changing visibility from View.VISIBLE to View.INVISIBLE. If nothing is set, the default will be to use the same transition as getExitTransition().
      Returns:
      the Transition to use to move Views into the scene when reentering from a previously-started Activity due to popping the back stack.
    • setSharedElementEnterTransition

      public void setSharedElementEnterTransition(@Nullable Transition transition)
      Sets the Transition that will be used for shared elements transferred into the content Scene. Typical Transitions will affect size and location, such as
      invalid reference
      ChangeBounds
      . A null value will cause transferred shared elements to blink to the final position.
      Parameters:
      transition - The Transition to use for shared elements transferred into the content Scene.
    • getSharedElementEnterTransition

      @Nullable public Transition getSharedElementEnterTransition()
      Returns the Transition that will be used for shared elements transferred into the content Scene. Typical Transitions will affect size and location, such as
      invalid reference
      ChangeBounds
      . A null value will cause transferred shared elements to blink to the final position.
      Returns:
      The Transition to use for shared elements transferred into the content Scene.
    • setSharedElementReturnTransition

      public void setSharedElementReturnTransition(@Nullable Transition transition)
      Sets the Transition that will be used for shared elements transferred back during a pop of the back stack. This Transition acts in the leaving Fragment. Typical Transitions will affect size and location, such as
      invalid reference
      ChangeBounds
      . A null value will cause transferred shared elements to blink to the final position. If no value is set, the default will be to use the same value as setSharedElementEnterTransition(Transition).
      Parameters:
      transition - The Transition to use for shared elements transferred out of the content Scene.
    • getSharedElementReturnTransition

      @Nullable public Transition getSharedElementReturnTransition()
      Return the Transition that will be used for shared elements transferred back during a pop of the back stack. This Transition acts in the leaving Fragment. Typical Transitions will affect size and location, such as
      invalid reference
      ChangeBounds
      . A null value will cause transferred shared elements to blink to the final position. If no value is set, the default will be to use the same value as setSharedElementEnterTransition(Transition).
      Returns:
      The Transition to use for shared elements transferred out of the content Scene.
    • 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 until startPostponedEnterTransition() or FragmentManager.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), or onCreateView(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

      public final void postponeEnterTransition(long duration, @NonNull TimeUnit timeUnit)
      Postpone the entering Fragment transition for a given amount of time and then call startPostponedEnterTransition().

      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), or onCreateView(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 in timeUnit units
      timeUnit - The units of time for duration
      See Also:
    • startPostponedEnterTransition

      public void startPostponedEnterTransition()
      Begin postponed transitions after postponeEnterTransition() was called. If postponeEnterTransition() was called, you must call startPostponedEnterTransition() or FragmentManager.executePendingTransactions() to complete the FragmentTransaction. If postponement was interrupted with FragmentManager.executePendingTransactions(), before startPostponedEnterTransition(), 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.