FragmentKt

Added in 1.3.0

public final class FragmentKt


Summary

Public methods

static final void

Clears the stored result for the given requestKey.

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

Clears the stored FragmentResultListener for the given requestKey.

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

Sets the given result for the requestKey.

static final void
setFragmentResultListener(
    @NonNull Fragment receiver,
    @NonNull String requestKey,
    @NonNull Function2<@NonNull String, @NonNull BundleUnit> listener
)

Sets the FragmentResultListener for a given requestKey.

Public methods

clearFragmentResult

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 setFragmentResult.

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

Parameters
@NonNull String requestKey

key used to identify the result

clearFragmentResultListener

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

Clears the stored FragmentResultListener for the given requestKey.

This clears a FragmentResultListener that was previously set a call to setFragmentResultListener.

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

Parameters
@NonNull String requestKey

key used to identify the result

setFragmentResult

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

Sets the given result for the requestKey. This result will be delivered to a FragmentResultListener that is called given to setFragmentResultListener with the same requestKey. If no FragmentResultListener with the same key is set or the Lifecycle associated with the listener is not at least androidx.lifecycle.Lifecycle.State.STARTED, the result is stored until one becomes available, or clearFragmentResult is called with the same requestKey.

Parameters
@NonNull String requestKey

key used to identify the result

@NonNull Bundle result

the result to be passed to another fragment.

setFragmentResultListener

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

Sets the FragmentResultListener for a given requestKey. Once this Fragment is at least in the androidx.lifecycle.Lifecycle.State.STARTED state, any results set by setFragmentResult using the same requestKey will be delivered to the FragmentResultListener.onFragmentResult callback. The callback will remain active until this Fragment reaches the androidx.lifecycle.Lifecycle.State.DESTROYED state or clearFragmentResultListener is called with the same requestKey.

Parameters
@NonNull requestKey: @NonNull String

requestKey used to store the result

@NonNull Function2<@NonNull String, @NonNull BundleUnit> listener

listener for result changes.