# FragmentKt

Added in 1.9.1

*** ** * ** ***


```
public final class FragmentKt
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentKt#(androidx.fragment.app.Fragment).clearFragmentResult(kotlin.String)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/Fragment receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html requestKey)` Clears the stored result for the given requestKey. |
| `static final void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentKt#(androidx.fragment.app.Fragment).clearFragmentResultListener(kotlin.String)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/Fragment receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html requestKey )` Clears the stored `https://developer.android.com/reference/androidx/fragment/app/FragmentResultListener` for the given requestKey. |
| `static final void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentKt#(androidx.fragment.app.Fragment).setFragmentResult(kotlin.String,android.os.Bundle)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/Fragment receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html requestKey, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/Bundle.html result )` Sets the given result for the `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).setFragmentResult(kotlin.String,android.os.Bundle)`. |
| `static final void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentKt#(androidx.fragment.app.Fragment).setFragmentResultListener(kotlin.String,kotlin.Function2)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/Fragment receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html requestKey, @https://developer.android.com/reference/androidx/annotation/NonNull Function2<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/Bundle.html, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> listener )` Sets the `https://developer.android.com/reference/androidx/fragment/app/FragmentResultListener` for a given `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).setFragmentResultListener(kotlin.String,kotlin.Function2)`. |

## Public methods

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

```
public static final void clearFragmentResult(@NonNull Fragment receiver, @NonNull String requestKey)
```

Clears the stored result for the given requestKey.

This clears a result that was previously set a call to `https://developer.android.com/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html requestKey` | key used to identify the result |

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

```
public static final void clearFragmentResultListener(
    @NonNull Fragment receiver,
    @NonNull String requestKey
)
```

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

This clears a `https://developer.android.com/reference/androidx/fragment/app/FragmentResultListener` that was previously set a call to `https://developer.android.com/reference/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/androidx/fragment/app/FragmentResultListener`, this method does nothing.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html requestKey` | key used to identify the result |

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

```
public static final void setFragmentResult(
    @NonNull Fragment receiver,
    @NonNull String requestKey,
    @NonNull Bundle result
)
```

Sets the given result for the `https://developer.android.com/reference/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/androidx/fragment/app/FragmentResultListener` that is called given to `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).setFragmentResultListener(kotlin.String,kotlin.Function2)` with the same `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).setFragmentResult(kotlin.String,android.os.Bundle)`. If no `https://developer.android.com/reference/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/androidx/lifecycle/Lifecycle.State#STARTED`, the result is stored until one becomes available, or `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).clearFragmentResult(kotlin.String)` is called with the same requestKey.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html requestKey` | key used to identify the result |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/Bundle.html result` | the result to be passed to another 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)

```
public static final void setFragmentResultListener(
    @NonNull Fragment receiver,
    @NonNull String requestKey,
    @NonNull Function2<@NonNull String, @NonNull Bundle, Unit> listener
)
```

Sets the `https://developer.android.com/reference/androidx/fragment/app/FragmentResultListener` for a given `https://developer.android.com/reference/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/androidx/lifecycle/Lifecycle.State#STARTED` state, any results set by `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).setFragmentResult(kotlin.String,android.os.Bundle)` using the same `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).setFragmentResultListener(kotlin.String,kotlin.Function2)` will be delivered to the `https://developer.android.com/reference/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/androidx/lifecycle/Lifecycle.State#DESTROYED` state or `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.Fragment).clearFragmentResultListener(kotlin.String)` is called with the same requestKey.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull requestKey: @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | requestKey used to store the result |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function2<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/Bundle.html, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> listener` | listener for result changes. |