FragmentManagerKt

Added in 1.1.0

public final class FragmentManagerKt


Summary

Public methods

static final void
commit(
    @NonNull FragmentManager receiver,
    boolean allowStateLoss,
    @ExtensionFunctionType @NonNull Function1<@NonNull FragmentTransactionUnit> body
)

Run body in a FragmentTransaction which is automatically committed if it completes without exception.

static final void
@MainThread
commitNow(
    @NonNull FragmentManager receiver,
    boolean allowStateLoss,
    @ExtensionFunctionType @NonNull Function1<@NonNull FragmentTransactionUnit> body
)

Run body in a FragmentTransaction which is automatically committed if it completes without exception.

static final void
transaction(
    @NonNull FragmentManager receiver,
    boolean now,
    boolean allowStateLoss,
    @ExtensionFunctionType @NonNull Function1<@NonNull FragmentTransactionUnit> body
)

This method is deprecated. Use commit { .. } or commitNow { .. } extensions

Public methods

public static final void commit(
    @NonNull FragmentManager receiver,
    boolean allowStateLoss,
    @ExtensionFunctionType @NonNull Function1<@NonNull FragmentTransactionUnit> body
)

Run body in a FragmentTransaction which is automatically committed if it completes without exception.

The transaction will be completed by calling FragmentTransaction.commit unless allowStateLoss is set to true in which case FragmentTransaction.commitAllowingStateLoss will be used.

commitNow

@MainThread
public static final void commitNow(
    @NonNull FragmentManager receiver,
    boolean allowStateLoss,
    @ExtensionFunctionType @NonNull Function1<@NonNull FragmentTransactionUnit> body
)

Run body in a FragmentTransaction which is automatically committed if it completes without exception.

The transaction will be completed by calling FragmentTransaction.commitNow unless allowStateLoss is set to true in which case FragmentTransaction.commitNowAllowingStateLoss will be used.

transaction

Added in 1.1.0
Deprecated in 1.1.0
public static final void transaction(
    @NonNull FragmentManager receiver,
    boolean now,
    boolean allowStateLoss,
    @ExtensionFunctionType @NonNull Function1<@NonNull FragmentTransactionUnit> body
)

Run body in a FragmentTransaction which is automatically committed if it completes without exception.

One of four commit functions will be used based on the values of now and allowStateLoss:

|  now  |  allowStateLoss  | Method                         |
| ----- | ---------------- | ------------------------------ |
| false | false            |  commit()                      |
| false | true             |  commitAllowingStateLoss()     |
| true  | false            |  commitNow()                   |
| true  | true             |  commitNowAllowingStateLoss()  |