# FragmentManagerKt

Added in 1.9.1

*** ** * ** ***


```
public final class FragmentManagerKt
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManagerKt#(androidx.fragment.app.FragmentManager).commit(kotlin.Boolean,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/FragmentManager receiver, boolean allowStateLoss, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> body )` Run `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentManager).commit(kotlin.Boolean,kotlin.Function1)` in a `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction` which is automatically committed if it completes without exception. |
| `static final void` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/fragment/app/FragmentManagerKt#(androidx.fragment.app.FragmentManager).commitNow(kotlin.Boolean,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/FragmentManager receiver, boolean allowStateLoss, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> body )` Run `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentManager).commitNow(kotlin.Boolean,kotlin.Function1)` in a `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction` which is automatically committed if it completes without exception. |
| `static final void` | `[transaction](https://developer.android.com/reference/androidx/fragment/app/FragmentManagerKt#(androidx.fragment.app.FragmentManager).transaction(kotlin.Boolean,kotlin.Boolean,kotlin.Function1))( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/FragmentManager receiver, boolean now, boolean allowStateLoss, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> body )` **This method is deprecated.** Use commit { .. } or commitNow { .. } extensions |

## Public methods

### commit

Artifact: [androidx.fragment:fragment](https://developer.android.com/jetpack/androidx/releases/fragment) [View Source](https://cs.android.com/search?q=file:androidx/fragment/app/FragmentManager.kt+function:commit) Added in [1.9.1](https://developer.android.com/jetpack/androidx/releases/fragment#1.9.1)

```
public static final void commit(
    @NonNull FragmentManager receiver,
    boolean allowStateLoss,
    @NonNull Function1<@NonNull FragmentTransaction, Unit> body
)
```

Run `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentManager).commit(kotlin.Boolean,kotlin.Function1)` in a `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction` which is automatically committed if it completes without exception.

The transaction will be completed by calling `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction#commit()` unless `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentManager).commit(kotlin.Boolean,kotlin.Function1)` is set to `true` in which case `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction#commitAllowingStateLoss()` will be used.

### commitNow

Artifact: [androidx.fragment:fragment](https://developer.android.com/jetpack/androidx/releases/fragment) [View Source](https://cs.android.com/search?q=file:androidx/fragment/app/FragmentManager.kt+function:commitNow) Added in [1.9.1](https://developer.android.com/jetpack/androidx/releases/fragment#1.9.1)

```
@MainThread
public static final void commitNow(
    @NonNull FragmentManager receiver,
    boolean allowStateLoss,
    @NonNull Function1<@NonNull FragmentTransaction, Unit> body
)
```

Run `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentManager).commitNow(kotlin.Boolean,kotlin.Function1)` in a `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction` which is automatically committed if it completes without exception.

The transaction will be completed by calling `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction#commitNow()` unless `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentManager).commitNow(kotlin.Boolean,kotlin.Function1)` is set to `true` in which case `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction#commitNowAllowingStateLoss()` will be used.

### transaction

Artifact: [androidx.fragment:fragment](https://developer.android.com/jetpack/androidx/releases/fragment) [View Source](https://cs.android.com/search?q=file:androidx/fragment/app/FragmentManager.kt+function:transaction) Added in [1.9.1](https://developer.android.com/jetpack/androidx/releases/fragment#1.9.1) Deprecated in [1.9.1](https://developer.android.com/jetpack/androidx/releases/fragment#1.9.1)

```
public static final void [transaction](https://developer.android.com/reference/androidx/fragment/app/FragmentManagerKt#(androidx.fragment.app.FragmentManager).transaction(kotlin.Boolean,kotlin.Boolean,kotlin.Function1))(
    @NonNull FragmentManager receiver,
    boolean now,
    boolean allowStateLoss,
    @NonNull Function1<@NonNull FragmentTransaction, Unit> body
)
```

> [!CAUTION]
> **This method is deprecated.**   
> Use commit { .. } or commitNow { .. } extensions

Run `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentManager).transaction(kotlin.Boolean,kotlin.Boolean,kotlin.Function1)` in a `https://developer.android.com/reference/androidx/fragment/app/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()  |
```