ActivityResultRegistry
abstract class ActivityResultRegistry
kotlin.Any | |
↳ | androidx.activity.result.ActivityResultRegistry |
A registry that stores activity result callbacks
for ActivityResultCaller#registerForActivityResult. You can create your own instance for testing by overriding onLaunch
and calling #dispatchResult immediately within it, thus skipping the actual Activity#startActivityForResult call. When testing, make sure to explicitly provide a registry instance whenever calling ActivityResultCaller#registerForActivityResult, to be able to inject a test instance.
Summary
Public constructors | |
---|---|
<init>() A registry that stores |
Public methods | |
---|---|
Boolean |
dispatchResult(requestCode: Int, resultCode: Int, @Nullable data: Intent?) Dispatch a result received via |
Boolean |
dispatchResult(requestCode: Int, result: O) Dispatch a result object to the callback on record. |
abstract Unit |
onLaunch(requestCode: Int, @NonNull contract: ActivityResultContract<I, O>, input: I, @Nullable options: ActivityOptionsCompat?) Start the process of executing an |
Unit |
onRestoreInstanceState(@Nullable savedInstanceState: Bundle?) Restore the state of this registry from the given |
Unit |
onSaveInstanceState(@NonNull outState: Bundle) Save the state of this registry in the given |
ActivityResultLauncher<I> |
register(@NonNull key: String, @NonNull lifecycleOwner: LifecycleOwner, @NonNull contract: ActivityResultContract<I, O>, @NonNull callback: ActivityResultCallback<O>) Register a new callback with this registry. |
ActivityResultLauncher<I> |
register(@NonNull key: String, @NonNull contract: ActivityResultContract<I, O>, @NonNull callback: ActivityResultCallback<O>) Register a new callback with this registry. |
Public constructors
<init>
ActivityResultRegistry()
A registry that stores activity result callbacks
for ActivityResultCaller#registerForActivityResult. You can create your own instance for testing by overriding onLaunch
and calling #dispatchResult immediately within it, thus skipping the actual Activity#startActivityForResult call. When testing, make sure to explicitly provide a registry instance whenever calling ActivityResultCaller#registerForActivityResult, to be able to inject a test instance.
Public methods
dispatchResult
@MainThread fun dispatchResult(
requestCode: Int,
resultCode: Int,
@Nullable data: Intent?
): Boolean
Dispatch a result received via Activity#onActivityResult
to the callback on record, or store the result if callback was not yet registered.
Parameters | |
---|---|
requestCode |
Int: request code to identify the callback |
resultCode |
Int: status to indicate the success of the operation |
data |
Intent?: an intent that carries the result data |
Return | |
---|---|
Boolean |
whether there was a callback was registered for the given request code which was or will be called. |