Google 致力于为黑人社区推动种族平等。查看具体举措

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 Activity#startActivityForResult, 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 Activity#startActivityForResult, designated by the given contract.

Extension functions
From androidx.activity.result
ActivityResultLauncher<Unit>
ActivityResultCaller.registerForActivityResult(contract: ActivityResultContract<I, O>, input: I, registry: ActivityResultRegistry, 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.

ActivityResultLauncher<Unit>
ActivityResultCaller.registerForActivityResult(contract: ActivityResultContract<I, O>, input: I, 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 Activity#startActivityForResult, 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