FragmentTransaction

public abstract class FragmentTransaction
extends Object

java.lang.Object
   ↳ androidx.fragment.app.FragmentTransaction


Static library support version of the framework's FragmentTransaction. Used to write apps that run on platforms prior to Android 3.0. When running on Android 3.0 or above, this implementation is still used; it does not try to switch to the framework's implementation. See the framework SDK documentation for a class overview.

Summary

Constants

int TRANSIT_ENTER_MASK

Bit mask that is set for all enter transitions.

int TRANSIT_EXIT_MASK

Bit mask that is set for all exit transitions.

int TRANSIT_FRAGMENT_CLOSE

Fragment is being removed from the stack

int TRANSIT_FRAGMENT_FADE

Fragment should simply fade in or out; that is, no strong navigation associated with it except that it is appearing or disappearing for some reason.

int TRANSIT_FRAGMENT_MATCH_ACTIVITY_CLOSE

Fragment is being removed from the stack with Activity close transition.

int TRANSIT_FRAGMENT_MATCH_ACTIVITY_OPEN

Fragment is being added onto the stack with Activity open transition.

int TRANSIT_FRAGMENT_OPEN

Fragment is being added onto the stack

int TRANSIT_NONE

No animation for transition.

int TRANSIT_UNSET

Not set up for a transition.

Public constructors

FragmentTransaction()

This constructor is deprecated. You should not instantiate a FragmentTransaction except via FragmentManager.beginTransaction().

Public methods

final FragmentTransaction add(int containerViewId, Class<? extends Fragment> fragmentClass, Bundle args)

Calls add(int, Class, Bundle, String) with a null tag.

FragmentTransaction add(int containerViewId, Fragment fragment, String tag)

Add a fragment to the activity state.

FragmentTransaction add(Fragment fragment, String tag)

Calls add(int, Fragment, String) with a 0 containerViewId.

final FragmentTransaction add(Class<? extends Fragment> fragmentClass, Bundle args, String tag)

Calls add(int, Class, Bundle, String) with a 0 containerViewId.

FragmentTransaction add(int containerViewId, Fragment fragment)

Calls add(int, Fragment, String) with a null tag.

final FragmentTransaction add(int containerViewId, Class<? extends Fragment> fragmentClass, Bundle args, String tag)

Add a fragment to the activity state.

FragmentTransaction addSharedElement(View sharedElement, String name)

Used with custom Transitions to map a View from a removed or hidden Fragment to a View from a shown or added Fragment.

FragmentTransaction addToBackStack(String name)

Add this transaction to the back stack.

FragmentTransaction attach(Fragment fragment)

Re-attach a fragment after it had previously been detached from the UI with detach(Fragment).

abstract int commit()

Schedules a commit of this transaction.

abstract int commitAllowingStateLoss()

Like commit() but allows the commit to be executed after an activity's state is saved.

abstract void commitNow()

Commits this transaction synchronously.

abstract void commitNowAllowingStateLoss()

Like commitNow() but allows the commit to be executed after an activity's state is saved.

FragmentTransaction detach(Fragment fragment)

Detach the given fragment from the UI.

FragmentTransaction disallowAddToBackStack()

Disallow calls to addToBackStack(String).

FragmentTransaction hide(Fragment fragment)

Hides an existing fragment.

boolean isAddToBackStackAllowed()

Returns true if this FragmentTransaction is allowed to be added to the back stack.

boolean isEmpty()
FragmentTransaction remove(Fragment fragment)

Remove an existing fragment.

FragmentTransaction replace(int containerViewId, Fragment fragment)

Calls replace(int, Fragment, String) with a null tag.

FragmentTransaction replace(int containerViewId, Fragment fragment, String tag)

Replace an existing fragment that was added to a container.

final FragmentTransaction replace(int containerViewId, Class<? extends Fragment> fragmentClass, Bundle args)

Calls replace(int, Class, Bundle, String) with a null tag.

final FragmentTransaction replace(int containerViewId, Class<? extends Fragment> fragmentClass, Bundle args, String tag)

Replace an existing fragment that was added to a container.

FragmentTransaction runOnCommit(Runnable runnable)

Add a Runnable to this transaction that will be run after this transaction has been committed.

FragmentTransaction setAllowOptimization(boolean allowOptimization)

This method is deprecated. This has been renamed setReorderingAllowed(boolean).

FragmentTransaction setBreadCrumbShortTitle(int res)

This method is deprecated. Store breadcrumb short titles separately from fragment transactions. For example, by using an android:label on a fragment in a navigation graph.

FragmentTransaction setBreadCrumbShortTitle(CharSequence text)

This method is deprecated. Store breadcrumb short titles separately from fragment transactions. For example, by using an android:label on a fragment in a navigation graph.

FragmentTransaction setBreadCrumbTitle(int res)

This method is deprecated. Store breadcrumb titles separately from fragment transactions. For example, by using an android:label on a fragment in a navigation graph.

FragmentTransaction setBreadCrumbTitle(CharSequence text)

This method is deprecated. Store breadcrumb titles separately from fragment transactions. For example, by using an android:label on a fragment in a navigation graph.

FragmentTransaction setCustomAnimations(int enter, int exit, int popEnter, int popExit)

Set specific animation resources to run for the fragments that are entering and exiting in this transaction.

FragmentTransaction setCustomAnimations(int enter, int exit)

Set specific animation resources to run for the fragments that are entering and exiting in this transaction.

FragmentTransaction setMaxLifecycle(Fragment fragment, Lifecycle.State state)

Set a ceiling for the state of an active fragment in this FragmentManager.

FragmentTransaction setPrimaryNavigationFragment(Fragment fragment)

Set a currently active fragment in this FragmentManager as the primary navigation fragment.

FragmentTransaction setReorderingAllowed(boolean reorderingAllowed)

Sets whether or not to allow optimizing operations within and across transactions.

FragmentTransaction setTransition(int transition)

Select a standard transition animation for this transaction.

FragmentTransaction setTransitionStyle(int styleRes)

This method is deprecated. The desired functionality never worked correctly. This should not be used.

FragmentTransaction show(Fragment fragment)

Shows a previously hidden fragment.

Inherited methods

Constants

TRANSIT_ENTER_MASK

public static final int TRANSIT_ENTER_MASK

Bit mask that is set for all enter transitions.

Constant Value: 4096 (0x00001000)

TRANSIT_EXIT_MASK

public static final int TRANSIT_EXIT_MASK

Bit mask that is set for all exit transitions.

Constant Value: 8192 (0x00002000)

TRANSIT_FRAGMENT_CLOSE

public static final int TRANSIT_FRAGMENT_CLOSE

Fragment is being removed from the stack

Constant Value: 8194 (0x00002002)

TRANSIT_FRAGMENT_FADE

public static final int TRANSIT_FRAGMENT_FADE

Fragment should simply fade in or out; that is, no strong navigation associated with it except that it is appearing or disappearing for some reason.

Constant Value: 4099 (0x00001003)

TRANSIT_FRAGMENT_MATCH_ACTIVITY_CLOSE

public static final int TRANSIT_FRAGMENT_MATCH_ACTIVITY_CLOSE

Fragment is being removed from the stack with Activity close transition.

Constant Value: 8197 (0x00002005)

TRANSIT_FRAGMENT_MATCH_ACTIVITY_OPEN

public static final int TRANSIT_FRAGMENT_MATCH_ACTIVITY_OPEN

Fragment is being added onto the stack with Activity open transition.

Constant Value: 4100 (0x00001004)

TRANSIT_FRAGMENT_OPEN

public static final int TRANSIT_FRAGMENT_OPEN

Fragment is being added onto the stack

Constant Value: 4097 (0x00001001)

TRANSIT_NONE

public static final int TRANSIT_NONE

No animation for transition.

Constant Value: 0 (0x00000000)

TRANSIT_UNSET

public static final int TRANSIT_UNSET

Not set up for a transition.

Constant Value: -1 (0xffffffff)

Public constructors

FragmentTransaction

public FragmentTransaction ()

This constructor is deprecated.
You should not instantiate a FragmentTransaction except via FragmentManager.beginTransaction().

Public methods

add

public