# androidx.fragment.app

*** ** * ** ***

## Interfaces

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager.BackStackEntry` | Representation of an entry on the fragment back stack, as created with `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentTransaction#addToBackStack(java.lang.String)`. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager.OnBackStackChangedListener` | Interface to watch for changes to the back stack. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentOnAttachListener` | Listener for receiving a callback immediately following `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment#onAttach(android.content.Context)`. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentResultListener` | Listener for handling fragment results. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentResultOwner` | A class that manages passing data between fragments. |

## Classes

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/DialogFragment` | A fragment that displays a dialog window, floating in the foreground of its activity's window. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment` | Static library support version of the framework's `https://developer.android.com/reference/android/app/Fragment.html`. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment.SavedState` | State information that has been retrieved from a fragment instance through `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager#saveFragmentInstanceState(androidx.fragment.app.Fragment)`. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentActivity` | Base class for activities that want to use the support-based `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment`. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentContainer` | Callbacks to a `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment`'s container. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentContainerView` | FragmentContainerView is a customized Layout designed specifically for Fragments. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentController` | Provides integration points with a `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager` for a fragment host. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory` | Interface used to control the instantiation of `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment` instances. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentHostCallback` | Integration points with the Fragment host. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager` | Static library support version of the framework's `https://developer.android.com/reference/android/app/FragmentManager.html`. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager.FragmentLifecycleCallbacks` | Callback interface for listening to fragment state changes that happen within a given FragmentManager. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManagerNonConfig` | **This class is deprecated.** Have your `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentHostCallback` implement `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner` to automatically retain the Fragment's non configuration state. <br /> |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter` | **This class is deprecated.** Switch to `https://developer.android.com/reference/kotlin/androidx/viewpager2/widget/ViewPager2` and use `https://developer.android.com/reference/kotlin/androidx/viewpager2/adapter/FragmentStateAdapter` instead. <br /> |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentStatePagerAdapter` | **This class is deprecated.** Switch to `https://developer.android.com/reference/kotlin/androidx/viewpager2/widget/ViewPager2` and use `https://developer.android.com/reference/kotlin/androidx/viewpager2/adapter/FragmentStateAdapter` instead. <br /> |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentTabHost` | **This class is deprecated.** Use [TabLayout and ViewPager](https://developer.android.com/guide/navigation/navigation-swipe-view) instead. <br /> |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentTransaction` | Static library support version of the framework's `https://developer.android.com/reference/android/app/FragmentTransaction.html`. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/ListFragment` | Static library support version of the framework's `https://developer.android.com/reference/android/app/ListFragment.html`. |

## Exceptions

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment.InstantiationException` | Thrown by `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory#instantiate(java.lang.ClassLoader,java.lang.String)` when there is an instantiation failure. |

## Annotations

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/PredictiveBackControl` |   |

## Extension functions summary

|---|---|
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-lazy/index.html<VM>` | `@https://developer.android.com/reference/kotlin/androidx/annotation/MainThread <VM : https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel> https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment.https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).activityViewModels(kotlin.Function0,kotlin.Function0)( noinline extrasProducer: (() -> https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/CreationExtras)?, noinline factoryProducer: (() -> https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider.Factory)? )` Returns a property delegate to access parent activity's `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel`, if `https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).activityViewModels(kotlin.Function0,kotlin.Function0)` is specified then `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider.Factory` returned by it will be used to create `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel` first time. |
| `inline https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentTransaction` | `<F : https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment> https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentTransaction.https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentTransaction).add(kotlin.String,android.os.Bundle)(tag: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, args: https://developer.android.com/reference/android/os/Bundle.html?)` Add a fragment to the associated `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager` without adding the Fragment to any container view. |
| `inline https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentTransaction` | `<F : https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment> https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentTransaction.https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentTransaction).add(kotlin.Int,kotlin.String,android.os.Bundle)( containerViewId: @https://developer.android.com/reference/kotlin/androidx/annotation/IdRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, tag: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, args: https://developer.android.com/reference/android/os/Bundle.html? )` Add a fragment to the associated `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager`, inflating the Fragment's view into the container view specified by `https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentTransaction).add(kotlin.Int,kotlin.String,android.os.Bundle)`, to later retrieve via `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager#findFragmentById(int)`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment.https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).clearFragmentResult(kotlin.String)(requestKey: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Clears the stored result for the given requestKey. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment.https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).clearFragmentResultListener(kotlin.String)(requestKey: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Clears the stored `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentResultListener` for the given requestKey. |
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager.https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentManager).commit(kotlin.Boolean,kotlin.Function1)(allowStateLoss: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, body: https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentTransaction.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Run `https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentManager).commit(kotlin.Boolean,kotlin.Function1)` in a `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentTransaction` which is automatically committed if it completes without exception. |
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/MainThread https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager.https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentManager).commitNow(kotlin.Boolean,kotlin.Function1)(allowStateLoss: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, body: https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentTransaction.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Run `https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentManager).commitNow(kotlin.Boolean,kotlin.Function1)` in a `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentTransaction` which is automatically committed if it completes without exception. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-lazy/index.html<VM>` | `@https://developer.android.com/reference/kotlin/androidx/annotation/MainThread <VM : https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel> https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment.https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).createViewModelLazy(kotlin.reflect.KClass,kotlin.Function0,kotlin.Function0,kotlin.Function0)( viewModelClass: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<VM>, storeProducer: () -> https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStore, extrasProducer: () -> https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/CreationExtras, factoryProducer: (() -> https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider.Factory)? )` Helper method for creation of `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelLazy`, that resolves `null` passed as `https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).createViewModelLazy(kotlin.reflect.KClass,kotlin.Function0,kotlin.Function0,kotlin.Function0)` to the default factory. |
| `F` | `<F : https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment> https://developer.android.com/reference/android/view/View.html.https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(android.view.View).findFragment()()` Find a `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment` associated with a `https://developer.android.com/reference/android/view/View.html`. |
| `inline https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentTransaction` | `<F : https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment> https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentTransaction.https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentTransaction).replace(kotlin.Int,kotlin.String,android.os.Bundle)( containerViewId: @https://developer.android.com/reference/kotlin/androidx/annotation/IdRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, tag: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, args: https://developer.android.com/reference/android/os/Bundle.html? )` Replace an existing fragment that was added to a container. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment.https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).setFragmentResult(kotlin.String,android.os.Bundle)(requestKey: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, result: https://developer.android.com/reference/android/os/Bundle.html)` Sets the given result for the `https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).setFragmentResult(kotlin.String,android.os.Bundle)`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment.https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).setFragmentResultListener(kotlin.String,kotlin.Function2)( requestKey: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, listener: (requestKey: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, bundle: https://developer.android.com/reference/android/os/Bundle.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Sets the `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentResultListener` for a given `https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).setFragmentResultListener(kotlin.String,kotlin.Function2)`. |
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager.[transaction](https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentManager).transaction(kotlin.Boolean,kotlin.Boolean,kotlin.Function1))( now: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, allowStateLoss: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, body: https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentTransaction.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` **This function is deprecated.** Use commit { .. } or commitNow { .. } extensions |
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-lazy/index.html<VM>` | `@https://developer.android.com/reference/kotlin/androidx/annotation/MainThread <VM : https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel> https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment.https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).viewModels(kotlin.Function0,kotlin.Function0,kotlin.Function0)( noinline ownerProducer: () -> https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner, noinline extrasProducer: (() -> https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/CreationExtras)?, noinline factoryProducer: (() -> https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider.Factory)? )` Returns a property delegate to access `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel` by **default** scoped to this `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment`: |

## Extension functions

### Fragment.activityViewModels

Artifact: [androidx.fragment:fragment](https://developer.android.com/jetpack/androidx/releases/fragment) [View Source](https://cs.android.com/search?q=file:androidx/fragment/app/FragmentViewModelLazy.kt+function:activityViewModels)

```
@MainThread
inline fun <VM : ViewModel> Fragment.activityViewModels(
    noinline extrasProducer: (() -> CreationExtras)? = null,
    noinline factoryProducer: (() -> ViewModelProvider.Factory)? = null
): Lazy<VM>
```

Returns a property delegate to access parent activity's `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel`, if `https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).activityViewModels(kotlin.Function0,kotlin.Function0)` is specified then `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider.Factory` returned by it will be used to create `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel` first time. Otherwise, the activity's default factory will be used.

```kotlin
class MyFragment : Fragment() {
    val viewmodel: MyViewModel by activityViewModels()
}
```

This property can be accessed only after this Fragment is attached i.e., after Fragment.onAttach(), and access prior to that will result in IllegalArgumentException.

### FragmentTransaction.add

Artifact: [androidx.fragment:fragment](https://developer.android.com/jetpack/androidx/releases/fragment) [View Source](https://cs.android.com/search?q=file:androidx/fragment/app/FragmentTransaction.kt+function:add)

```
inline fun <F : Fragment> FragmentTransaction.add(tag: String, args: Bundle? = null): FragmentTransaction
```

Add a fragment to the associated `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager` without adding the Fragment to any container view.

The new fragment to be added will be created via the `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory` of the `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager`.

| Parameters |
|---|---|
| `tag: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | Tag name for the fragment, to later retrieve the fragment with `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager#findFragmentByTag(java.lang.String)`. |
| `args: https://developer.android.com/reference/android/os/Bundle.html? = null` | Optional arguments to be set on the fragment. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentTransaction` | Returns the same `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentTransaction` instance. |

### FragmentTransaction.add

Artifact: [androidx.fragment:fragment](https://developer.android.com/jetpack/androidx/releases/fragment) [View Source](https://cs.android.com/search?q=file:androidx/fragment/app/FragmentTransaction.kt+function:add)

```
inline fun <F : Fragment> FragmentTransaction.add(
    containerViewId: @IdRes Int,
    tag: String? = null,
    args: Bundle? = null
): FragmentTransaction
```

Add a fragment to the associated `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager`, inflating the Fragment's view into the container view specified by `https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentTransaction).add(kotlin.Int,kotlin.String,android.os.Bundle)`, to later retrieve via `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager#findFragmentById(int)`.

The new fragment to be added will be created via the `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory` of the `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager`.

| Parameters |
|---|---|
| `containerViewId: @https://developer.android.com/reference/kotlin/androidx/annotation/IdRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Identifier of the container this fragment is to be placed in. |
| `tag: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html? = null` | Optional tag name for the fragment, to later retrieve the fragment with `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager#findFragmentByTag(java.lang.String)`. |
| `args: https://developer.android.com/reference/android/os/Bundle.html? = null` | Optional arguments to be set on the fragment. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentTransaction` | Returns the same `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentTransaction` instance. |

### Fragment.clearFragmentResult

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

```
fun Fragment.clearFragmentResult(requestKey: String): Unit
```

Clears the stored result for the given requestKey.

This clears a result that was previously set a call to `https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).setFragmentResult(kotlin.String,android.os.Bundle)`.

If this is called with a requestKey that is not associated with any result, this method does nothing.

| Parameters |
|---|---|
| `requestKey: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | key used to identify the result |

### Fragment.clearFragmentResultListener

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

```
fun Fragment.clearFragmentResultListener(requestKey: String): Unit
```

Clears the stored `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentResultListener` for the given requestKey.

This clears a `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentResultListener` that was previously set a call to `https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).setFragmentResultListener(kotlin.String,kotlin.Function2)`.

If this is called with a requestKey that is not associated with any `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentResultListener`, this method does nothing.

| Parameters |
|---|---|
| `requestKey: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | key used to identify the result |

### FragmentManager.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)

```
inline fun FragmentManager.commit(allowStateLoss: Boolean = false, body: FragmentTransaction.() -> Unit): Unit
```

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

### FragmentManager.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
inline fun FragmentManager.commitNow(allowStateLoss: Boolean = false, body: FragmentTransaction.() -> Unit): Unit
```

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

### Fragment.createViewModelLazy

Artifact: [androidx.fragment:fragment](https://developer.android.com/jetpack/androidx/releases/fragment) [View Source](https://cs.android.com/search?q=file:androidx/fragment/app/FragmentViewModelLazy.kt+function:createViewModelLazy)

```
@MainThread
fun <VM : ViewModel> Fragment.createViewModelLazy(
    viewModelClass: KClass<VM>,
    storeProducer: () -> ViewModelStore,
    extrasProducer: () -> CreationExtras = { defaultViewModelCreationExtras },
    factoryProducer: (() -> ViewModelProvider.Factory)? = null
): Lazy<VM>
```

Helper method for creation of `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelLazy`, that resolves `null` passed as `https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).createViewModelLazy(kotlin.reflect.KClass,kotlin.Function0,kotlin.Function0,kotlin.Function0)` to the default factory.

This method also takes a `https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/CreationExtras` producer that provides default extras to the created `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel`.

### View.findFragment

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

```
fun <F : Fragment> View.findFragment(): F
```

Find a `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment` associated with a `https://developer.android.com/reference/android/view/View.html`.

This method will locate the `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment` associated with this view. This is automatically populated for the View returned by `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment#onCreateView(android.view.LayoutInflater,android.view.ViewGroup,android.os.Bundle)` and its children.

Calling this on a View that does not have a Fragment set will result in an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html`

### FragmentTransaction.replace

Artifact: [androidx.fragment:fragment](https://developer.android.com/jetpack/androidx/releases/fragment) [View Source](https://cs.android.com/search?q=file:androidx/fragment/app/FragmentTransaction.kt+function:replace)

```
inline fun <F : Fragment> FragmentTransaction.replace(
    containerViewId: @IdRes Int,
    tag: String? = null,
    args: Bundle? = null
): FragmentTransaction
```

Replace an existing fragment that was added to a container. This is essentially the same as calling `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentTransaction#remove(androidx.fragment.app.Fragment)` for all currently added fragments that were added with the same `containerViewId` and then `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentTransaction#add(java.lang.Class<? extends androidx.fragment.app.Fragment>,android.os.Bundle,java.lang.String)` with the same arguments given here.

The new fragment to place in the container will be created via the `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory` of the `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager`.

| Parameters |
|---|---|
| `containerViewId: @https://developer.android.com/reference/kotlin/androidx/annotation/IdRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Identifier of the container whose fragment(s) are to be replaced. |
| `tag: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html? = null` | Optional tag name for the fragment, to later retrieve the fragment with `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager#findFragmentByTag(java.lang.String)`. |
| `args: https://developer.android.com/reference/android/os/Bundle.html? = null` | Optional arguments to be set on the fragment. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentTransaction` | Returns the same `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentTransaction` instance. |

### Fragment.setFragmentResult

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

```
fun Fragment.setFragmentResult(requestKey: String, result: Bundle): Unit
```

Sets the given result for the `https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).setFragmentResult(kotlin.String,android.os.Bundle)`. This result will be delivered to a `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentResultListener` that is called given to `https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).setFragmentResultListener(kotlin.String,kotlin.Function2)` with the same `https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).setFragmentResult(kotlin.String,android.os.Bundle)`. If no `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentResultListener` with the same key is set or the Lifecycle associated with the listener is not at least `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#STARTED`, the result is stored until one becomes available, or `https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).clearFragmentResult(kotlin.String)` is called with the same requestKey.

| Parameters |
|---|---|
| `requestKey: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | key used to identify the result |
| `result: https://developer.android.com/reference/android/os/Bundle.html` | the result to be passed to another fragment. |

### Fragment.setFragmentResultListener

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

```
fun Fragment.setFragmentResultListener(
    requestKey: String,
    listener: (requestKey: String, bundle: Bundle) -> Unit
): Unit
```

Sets the `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentResultListener` for a given `https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).setFragmentResultListener(kotlin.String,kotlin.Function2)`. Once this Fragment is at least in the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#STARTED` state, any results set by `https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).setFragmentResult(kotlin.String,android.os.Bundle)` using the same `https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).setFragmentResultListener(kotlin.String,kotlin.Function2)` will be delivered to the `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentResultListener#onFragmentResult(java.lang.String,android.os.Bundle)` callback. The callback will remain active until this Fragment reaches the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#DESTROYED` state or `https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).clearFragmentResultListener(kotlin.String)` is called with the same requestKey.

| Parameters |
|---|---|
| `requestKey: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | requestKey used to store the result |
| `listener: (requestKey: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, bundle: https://developer.android.com/reference/android/os/Bundle.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | listener for result changes. |

### FragmentManager.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)

```
inline fun FragmentManager.[transaction](https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentManager).transaction(kotlin.Boolean,kotlin.Boolean,kotlin.Function1))(
    now: Boolean = false,
    allowStateLoss: Boolean = false,
    body: FragmentTransaction.() -> Unit
): Unit
```

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

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

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

### Fragment.viewModels

Artifact: [androidx.fragment:fragment](https://developer.android.com/jetpack/androidx/releases/fragment) [View Source](https://cs.android.com/search?q=file:androidx/fragment/app/FragmentViewModelLazy.kt+function:viewModels)

```
@MainThread
inline fun <VM : ViewModel> Fragment.viewModels(
    noinline ownerProducer: () -> ViewModelStoreOwner = { this },
    noinline extrasProducer: (() -> CreationExtras)? = null,
    noinline factoryProducer: (() -> ViewModelProvider.Factory)? = null
): Lazy<VM>
```

Returns a property delegate to access `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel` by **default** scoped to this `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment`:

```kotlin
class MyFragment : Fragment() {
    val viewmodel: MyViewModel by viewModels()
}
```

Custom `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelProvider.Factory` can be defined via `https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).viewModels(kotlin.Function0,kotlin.Function0,kotlin.Function0)` parameter, factory returned by it will be used to create `https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModel`:

```kotlin
class MyFragment : Fragment() {
    val viewmodel: MyViewModel by viewModels { myFactory }
}
```

Default scope may be overridden with parameter `https://developer.android.com/reference/kotlin/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).viewModels(kotlin.Function0,kotlin.Function0,kotlin.Function0)`:

```kotlin
class MyFragment : Fragment() {
    val viewmodel: MyViewModel by viewModels ({requireParentFragment()})
}
```

This property can be accessed only after this Fragment is attached i.e., after Fragment.onAttach(), and access prior to that will result in IllegalArgumentException.