# ActivityResultRegistry

Artifact: [androidx.activity:activity](https://developer.android.com/jetpack/androidx/releases/activity) [View Source](https://cs.android.com/search?q=file:androidx/activity/result/ActivityResultRegistry.kt+class:androidx.activity.result.ActivityResultRegistry) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/activity#1.2.0)

*** ** * ** ***

<br />

```
abstract class ActivityResultRegistry
```

<br />

*** ** * ** ***

A registry that stores `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultCallback` for `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultCaller#registerForActivityResult(androidx.activity.result.contract.ActivityResultContract,androidx.activity.result.ActivityResultCallback)`.

You can create your own instance for testing by overriding `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultRegistry#onLaunch(kotlin.Int,androidx.activity.result.contract.ActivityResultContract,kotlin.Any,androidx.core.app.ActivityOptionsCompat)` and calling `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultRegistry#dispatchResult(kotlin.Int,kotlin.Int,android.content.Intent)` immediately within it, thus skipping the actual `https://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.Intent, int)` call.

When testing, make sure to explicitly provide a registry instance whenever calling `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultCaller#registerForActivityResult(androidx.activity.result.contract.ActivityResultContract,androidx.activity.result.ActivityResultCallback)`, to be able to inject a test instance.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultRegistry#ActivityResultRegistry()()` |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/MainThread <O : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultRegistry#dispatchResult(kotlin.Int,kotlin.Any)(requestCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, result: O)` Dispatch a result object to the callback on record. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/MainThread https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultRegistry#dispatchResult(kotlin.Int,kotlin.Int,android.content.Intent)(requestCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, resultCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, data: https://developer.android.com/reference/android/content/Intent.html?)` Dispatch a result received via `https://developer.android.com/reference/android/app/Activity.html#onActivityResult(int, int, android.content.Intent)` to the callback on record, or store the result if callback was not yet registered. |
| `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/MainThread <I : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, O : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultRegistry#onLaunch(kotlin.Int,androidx.activity.result.contract.ActivityResultContract,kotlin.Any,androidx.core.app.ActivityOptionsCompat)( requestCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, contract: https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContract<I, O>, input: I, options: https://developer.android.com/reference/kotlin/androidx/core/app/ActivityOptionsCompat? )` Start the process of executing an `https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContract` in a type-safe way, using the provided `https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContract`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultRegistry#onRestoreInstanceState(android.os.Bundle)(savedInstanceState: https://developer.android.com/reference/android/os/Bundle.html?)` Restore the state of this registry from the given `https://developer.android.com/reference/android/os/Bundle.html` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultRegistry#onSaveInstanceState(android.os.Bundle)(outState: https://developer.android.com/reference/android/os/Bundle.html)` Save the state of this registry in the given `https://developer.android.com/reference/android/os/Bundle.html` |
| `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultLauncher<I>` | `<I : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, O : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultRegistry#register(kotlin.String,androidx.activity.result.contract.ActivityResultContract,androidx.activity.result.ActivityResultCallback)( key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, contract: https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContract<I, O>, callback: https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultCallback<O> )` Register a new callback with this registry. |
| `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultLauncher<I>` | `<I : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, O : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultRegistry#register(kotlin.String,androidx.lifecycle.LifecycleOwner,androidx.activity.result.contract.ActivityResultContract,androidx.activity.result.ActivityResultCallback)( key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, lifecycleOwner: https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner, contract: https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContract<I, O>, callback: https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultCallback<O> )` Register a new callback with this registry. |

## Public constructors

### ActivityResultRegistry

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/activity#1.2.0)

```
ActivityResultRegistry()
```

## Public functions

### dispatchResult

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/activity#1.2.0)

```
@MainThread
fun <O : Any?> dispatchResult(requestCode: Int, result: O): Boolean
```

Dispatch a result object to the callback on record.

| Parameters |
|---|---|
| `requestCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | request code to identify the callback |
| `result: O` | the result to propagate |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if there is a callback registered for the given request code, false otherwise. |

### dispatchResult

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/activity#1.2.0)

```
@MainThread
fun dispatchResult(requestCode: Int, resultCode: Int, data: Intent?): Boolean
```

Dispatch a result received via `https://developer.android.com/reference/android/app/Activity.html#onActivityResult(int, int, android.content.Intent)` to the callback on record, or store the result if callback was not yet registered.

| Parameters |
|---|---|
| `requestCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | request code to identify the callback |
| `resultCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | status to indicate the success of the operation |
| `data: https://developer.android.com/reference/android/content/Intent.html?` | an intent that carries the result data |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | whether there was a callback was registered for the given request code which was or will be called. |

### onLaunch

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/activity#1.2.0)

```
@MainThread
abstract fun <I : Any?, O : Any?> onLaunch(
    requestCode: Int,
    contract: ActivityResultContract<I, O>,
    input: I,
    options: ActivityOptionsCompat?
): Unit
```

Start the process of executing an `https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContract` in a type-safe way, using the provided `https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContract`.

| Parameters |
|---|---|
| `requestCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | request code to use |
| `contract: https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContract<I, O>` | contract to use for type conversions |
| `input: I` | input required to execute an ActivityResultContract. |
| `options: https://developer.android.com/reference/kotlin/androidx/core/app/ActivityOptionsCompat?` | Additional options for how the Activity should be started. |

### onRestoreInstanceState

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/activity#1.2.0)

```
fun onRestoreInstanceState(savedInstanceState: Bundle?): Unit
```

Restore the state of this registry from the given `https://developer.android.com/reference/android/os/Bundle.html`

| Parameters |
|---|---|
| `savedInstanceState: https://developer.android.com/reference/android/os/Bundle.html?` | the place to restore from |

### onSaveInstanceState

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/activity#1.2.0)

```
fun onSaveInstanceState(outState: Bundle): Unit
```

Save the state of this registry in the given `https://developer.android.com/reference/android/os/Bundle.html`

| Parameters |
|---|---|
| `outState: https://developer.android.com/reference/android/os/Bundle.html` | the place to put state into |

### register

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/activity#1.2.0)

```
fun <I : Any?, O : Any?> register(
    key: String,
    contract: ActivityResultContract<I, O>,
    callback: ActivityResultCallback<O>
): ActivityResultLauncher<I>
```

Register a new callback with this registry.

This is normally called by a higher level convenience methods like `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultCaller#registerForActivityResult(androidx.activity.result.contract.ActivityResultContract,androidx.activity.result.ActivityResultCallback)`.

When calling this, you must call `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultLauncher#unregister()` on the returned `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultLauncher` when the launcher is no longer needed to release any values that might be captured in the registered callback.

| Parameters |
|---|---|
| `key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | a unique string key identifying this call |
| `contract: https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContract<I, O>` | the contract specifying input/output types of the call |
| `callback: https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultCallback<O>` | the activity result callback |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultLauncher<I>` | a launcher that can be used to execute an ActivityResultContract. |

### register

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/activity#1.2.0)

```
fun <I : Any?, O : Any?> register(
    key: String,
    lifecycleOwner: LifecycleOwner,
    contract: ActivityResultContract<I, O>,
    callback: ActivityResultCallback<O>
): ActivityResultLauncher<I>
```

Register a new callback with this registry.

This is normally called by a higher level convenience methods like `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultCaller#registerForActivityResult(androidx.activity.result.contract.ActivityResultContract,androidx.activity.result.ActivityResultCallback)`.

| Parameters |
|---|---|
| `key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | a unique string key identifying this call |
| `lifecycleOwner: https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner` | a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner` that makes this call. |
| `contract: https://developer.android.com/reference/kotlin/androidx/activity/result/contract/ActivityResultContract<I, O>` | the contract specifying input/output types of the call |
| `callback: https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultCallback<O>` | the activity result callback |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultLauncher<I>` | a launcher that can be used to execute an ActivityResultContract. |