androidx.activity.result


Interfaces

ActivityResultCallback

A type-safe callback to be called when an activity result is available.

ActivityResultCaller

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

ActivityResultRegistryOwner

A class that has an ActivityResultRegistry that allows you to register a ActivityResultCallback for handling an androidx.activity.result.contract.ActivityResultContract.

Classes

Top-level functions summary

Extension functions summary

operator Int

Destructuring declaration for ActivityResult to provide the requestCode

operator Intent?

Destructuring declaration for ActivityResult to provide the intent

Unit

Convenience method to launch a no-argument registered call without needing to pass in null.

Unit

Convenience method to launch a no-argument registered call without needing to pass in Unit.

ActivityResultLauncher<Unit>
<I : Any?, O : Any?> 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.

ActivityResultLauncher<Unit>
<I : Any?, O : Any?> 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.

Top-level functions

PickVisualMediaRequest

fun PickVisualMediaRequest(
    mediaType: ActivityResultContracts.PickVisualMedia.VisualMediaType = ImageAndVideo,
    maxItems: @IntRange(from = 2) Int = PickMultipleVisualMedia.getMaxItems(),
    isOrderedSelection: Boolean = false,
    defaultTab: ActivityResultContracts.PickVisualMedia.DefaultTab = DefaultTab.PhotosTab
): PickVisualMediaRequest

Creates a request for a androidx.activity.result.contract.ActivityResultContracts.PickMultipleVisualMedia or androidx.activity.result.contract.ActivityResultContracts.PickVisualMedia Activity Contract.

Parameters
mediaType: ActivityResultContracts.PickVisualMedia.VisualMediaType = ImageAndVideo

type to go into the PickVisualMediaRequest

maxItems: @IntRange(from = 2) Int = PickMultipleVisualMedia.getMaxItems()

limit the number of selectable items when using PickMultipleVisualMedia

isOrderedSelection: Boolean = false

whether the user can control the order of selected media when using PickMultipleVisualMedia (defaults to false)

defaultTab: ActivityResultContracts.PickVisualMedia.DefaultTab = DefaultTab.PhotosTab

the tab to initially open in the picker (defaults to DefaultTab.PhotosTab)

Returns
PickVisualMediaRequest

a PickVisualMediaRequest that contains the given input

PickVisualMediaRequest

fun PickVisualMediaRequest(
    accentColor: Long,
    mediaType: ActivityResultContracts.PickVisualMedia.VisualMediaType = ImageAndVideo,
    maxItems: @IntRange(from = 2) Int = PickMultipleVisualMedia.getMaxItems(),
    isOrderedSelection: Boolean = false,
    defaultTab: ActivityResultContracts.PickVisualMedia.DefaultTab = DefaultTab.PhotosTab
): PickVisualMediaRequest

Creates a request for a androidx.activity.result.contract.ActivityResultContracts.PickMultipleVisualMedia or androidx.activity.result.contract.ActivityResultContracts.PickVisualMedia Activity Contract.

Parameters
accentColor: Long

color long to customize picker accent color

mediaType: ActivityResultContracts.PickVisualMedia.VisualMediaType = ImageAndVideo

type to go into the PickVisualMediaRequest

maxItems: @IntRange(from = 2) Int = PickMultipleVisualMedia.getMaxItems()

limit the number of selectable items when using PickMultipleVisualMedia

isOrderedSelection: Boolean = false

whether the user can control the order of selected media when using PickMultipleVisualMedia (defaults to false)

defaultTab: ActivityResultContracts.PickVisualMedia.DefaultTab = DefaultTab.PhotosTab

the tab to initially open in the picker (defaults to DefaultTab.PhotosTab)

Returns
PickVisualMediaRequest

a PickVisualMediaRequest that contains the given input

Extension functions

component1

operator fun ActivityResult.component1(): Int

Destructuring declaration for ActivityResult to provide the requestCode

Returns
Int

the resultCode of the ActivityResult

component2

operator fun ActivityResult.component2(): Intent?

Destructuring declaration for ActivityResult to provide the intent

Returns
Intent?

the intent of the ActivityResult

launch

fun ActivityResultLauncher<Void?>.launch(
    options: ActivityOptionsCompat? = null
): Unit

Convenience method to launch a no-argument registered call without needing to pass in null.

launch

fun ActivityResultLauncher<Unit>.launch(
    options: ActivityOptionsCompat? = null
): Unit

Convenience method to launch a no-argument registered call without needing to pass in Unit.

registerForActivityResult

fun <I : Any?, O : Any?> ActivityResultCaller.registerForActivityResult(
    contract: ActivityResultContract<I, O>,
    input: I,
    callback: (O) -> Unit
): ActivityResultLauncher<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.

registerForActivityResult

fun <I : Any?, O : Any?> ActivityResultCaller.registerForActivityResult(
    contract: ActivityResultContract<I, O>,
    input: I,
    registry: ActivityResultRegistry,
    callback: (O) -> Unit
): ActivityResultLauncher<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.