ActivityResultCaller

interface ActivityResultCaller
androidx.activity.result.ActivityResultCaller

A class that can call Activity#startActivityForResult-style APIs without having to manage request codes, and converting request/response to an Intent

Summary

Public methods

abstract ActivityResultLauncher<I>
registerForActivityResult(@NonNull contract: ActivityResultContract<I, O>, @NonNull callback: ActivityResultCallback<O>)

Register a request to start an activity for result, designated by the given contract.

abstract ActivityResultLauncher<I>
registerForActivityResult(@NonNull contract: ActivityResultContract<I, O>, @NonNull registry: ActivityResultRegistry, @NonNull callback: ActivityResultCallback<O>)

Register a request to start an activity for result, designated by the given contract.

Extension functions

From androidx.activity.result
() -> Unit
ActivityResultCaller.registerForActivityResult(contract: ActivityResultContract<I, O>, input: I, registry: ActivityResultRegistry, crossinline callback: (O) -> Unit)

A version of ActivityResultCaller.registerForActivityResult that additionally takes an input right away, producing a launcher that doesn't take any additional input when called.

() -> Unit
ActivityResultCaller.registerForActivityResult(contract: ActivityResultContract<I, O>, input: I, crossinline callback: (O) -> Unit)

A version of ActivityResultCaller.registerForActivityResult that additionally takes an input right away, producing a launcher that doesn't take any additional input when called.

Public methods

registerForActivityResult

@NonNull abstract fun <I : Any!, O : Any!> registerForActivityResult(
    @NonNull contract: ActivityResultContract<I, O>,
    @NonNull callback: ActivityResultCallback<O>
): ActivityResultLauncher<I>

Register a request to start an activity for result, designated by the given contract. This creates a record in the registry associated wit this caller, managing request code, as well as conversions to/from Intent under the hood. This *must* be called unconditionally, as part of initialization path, typically as a field initializer of an Activity or Fragment.

Parameters
<I> the type of the input(if any) required to call the activity
<O> the type of output returned as an activity result
contract ActivityResultContract<I, O>: the contract, specifying conversions to/from Intents
callback ActivityResultCallback<O>: the callback to be called on the main thread when activity result is available
Return
ActivityResultLauncher<I> the launcher that can be used to start the activity or dispose of the prepared call.

registerForActivityResult

@NonNull abstract fun <I : Any!, O : Any!> registerForActivityResult(
    @NonNull contract: ActivityResultContract<I, O>,
    @NonNull registry: ActivityResultRegistry,
    @NonNull callback: ActivityResultCallback<O>
): ActivityResultLauncher<I>

Register a request to start an activity for result, designated by the given contract. This creates a record in the given registry, managing request code, as well as conversions to/from Intent under the hood. This *must* be called unconditionally, as part of initialization path, typically as a field initializer of an Activity or Fragment.

Parameters
<I> the type of the input(if any) required to call the activity
<O> the type of output returned as an activity result
contract ActivityResultContract<I, O>: the contract, specifying conversions to/from Intents
registry ActivityResultRegistry: the registry where to hold the record.
callback ActivityResultCallback<O>: the callback to be called on the main thread when activity result is available
Return
ActivityResultLauncher<I> the launcher that can be used to start the activity or dispose of the prepared call.