ActivityResultRegistry

public abstract class ActivityResultRegistry


A registry that stores activity result callbacks for registered calls. You can create your own instance for testing by overriding onLaunch and calling dispatchResult immediately within it, thus skipping the actual startActivityForResult call. When testing, make sure to explicitly provide a registry instance whenever calling registerForActivityResult, to be able to inject a test instance.

Summary

Public constructors

Public methods

final @MainThread boolean
dispatchResult(int requestCode, int resultCode, @Nullable Intent data)

Dispatch a result received via onActivityResult to the callback on record, or store the result if callback was not yet registered.

final @MainThread boolean
<O> dispatchResult(int requestCode, O result)

Dispatch a result object to the callback on record.

abstract @MainThread void
<I, O> onLaunch(
    int requestCode,
    @NonNull ActivityResultContract<I, O> contract,
    I input,
    @Nullable ActivityOptionsCompat options
)

Start the process of executing an ActivityResultContract in a type-safe way, using the provided contract.

final void
onRestoreInstanceState(@Nullable Bundle savedInstanceState)

Restore the state of this registry from the given Bundle

final void

Save the state of this registry in the given Bundle

final @NonNull ActivityResultLauncher<I>
<I, O> register(
    @NonNull String key,
    @NonNull LifecycleOwner lifecycleOwner,
    @NonNull ActivityResultContract<I, O> contract,
    @NonNull ActivityResultCallback<O> callback
)

Register a new callback with this registry.

final @NonNull ActivityResultLauncher<I>
<I, O> register(
    @NonNull String key,
    @NonNull ActivityResultContract<I, O> contract,
    @NonNull ActivityResultCallback<O> callback
)

Register a new callback with this registry.

Publi