# 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 />

```
public abstract class ActivityResultRegistry
```

<br />

*** ** * ** ***

A registry that stores `https://developer.android.com/reference/androidx/activity/result/ActivityResultCallback` for `https://developer.android.com/reference/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/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/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/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/androidx/activity/result/ActivityResultRegistry#ActivityResultRegistry()()` |

| ### Public methods |
|---|---|
| `final boolean` | `@https://developer.android.com/reference/androidx/annotation/MainThread <O extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/activity/result/ActivityResultRegistry#dispatchResult(kotlin.Int,kotlin.Any)(int requestCode, @https://developer.android.com/reference/androidx/annotation/NonNull O result)` Dispatch a result object to the callback on record. |
| `final boolean` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/activity/result/ActivityResultRegistry#dispatchResult(kotlin.Int,kotlin.Int,android.content.Intent)(int requestCode, int resultCode, https://developer.android.com/reference/android/content/Intent.html data)` 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 void` | `@https://developer.android.com/reference/androidx/annotation/MainThread <I extends https://developer.android.com/reference/java/lang/Object.html, O extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/activity/result/ActivityResultRegistry#onLaunch(kotlin.Int,androidx.activity.result.contract.ActivityResultContract,kotlin.Any,androidx.core.app.ActivityOptionsCompat)( int requestCode, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/activity/result/contract/ActivityResultContract<@https://developer.android.com/reference/androidx/annotation/NonNull I, @https://developer.android.com/reference/androidx/annotation/NonNull O> contract, @https://developer.android.com/reference/androidx/annotation/NonNull I input, https://developer.android.com/reference/androidx/core/app/ActivityOptionsCompat options )` Start the process of executing an `https://developer.android.com/reference/androidx/activity/result/contract/ActivityResultContract` in a type-safe way, using the provided `https://developer.android.com/reference/androidx/activity/result/contract/ActivityResultContract`. |
| `final void` | `https://developer.android.com/reference/androidx/activity/result/ActivityResultRegistry#onRestoreInstanceState(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle.html savedInstanceState)` Restore the state of this registry from the given `https://developer.android.com/reference/android/os/Bundle.html` |
| `final void` | `https://developer.android.com/reference/androidx/activity/result/ActivityResultRegistry#onSaveInstanceState(android.os.Bundle)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/Bundle.html outState)` Save the state of this registry in the given `https://developer.android.com/reference/android/os/Bundle.html` |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/activity/result/ActivityResultLauncher<@https://developer.android.com/reference/androidx/annotation/NonNull I>` | `<I extends https://developer.android.com/reference/java/lang/Object.html, O extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/activity/result/ActivityResultRegistry#register(kotlin.String,androidx.activity.result.contract.ActivityResultContract,androidx.activity.result.ActivityResultCallback)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html key, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/activity/result/contract/ActivityResultContract<@https://developer.android.com/reference/androidx/annotation/NonNull I, @https://developer.android.com/reference/androidx/annotation/NonNull O> contract, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/activity/result/ActivityResultCallback<@https://developer.android.com/reference/androidx/annotation/NonNull O> callback )` Register a new callback with this registry. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/activity/result/ActivityResultLauncher<@https://developer.android.com/reference/androidx/annotation/NonNull I>` | `<I extends https://developer.android.com/reference/java/lang/Object.html, O extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/activity/result/ActivityResultRegistry#register(kotlin.String,androidx.lifecycle.LifecycleOwner,androidx.activity.result.contract.ActivityResultContract,androidx.activity.result.ActivityResultCallback)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html key, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner lifecycleOwner, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/activity/result/contract/ActivityResultContract<@https://developer.android.com/reference/androidx/annotation/NonNull I, @https://developer.android.com/reference/androidx/annotation/NonNull O> contract, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/activity/result/ActivityResultCallback<@https://developer.android.com/reference/androidx/annotation/NonNull O> callback )` 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)

```
public ActivityResultRegistry()
```

## Public methods

### dispatchResult

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

```
@MainThread
public final boolean <O extends Object> dispatchResult(int requestCode, @NonNull O result)
```

Dispatch a result object to the callback on record.

| Parameters |
|---|---|
| `int requestCode` | request code to identify the callback |
| `@https://developer.android.com/reference/androidx/annotation/NonNull O result` | the result to propagate |

| Returns |
|---|---|
| `boolean` | 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
public final boolean dispatchResult(int requestCode, int resultCode, Intent data)
```

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 |
|---|---|
| `int requestCode` | request code to identify the callback |
| `int resultCode` | status to indicate the success of the operation |
| `https://developer.android.com/reference/android/content/Intent.html data` | an intent that carries the result data |

| Returns |
|---|---|
| `boolean` | 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
public abstract void <I extends Object, O extends Object> onLaunch(
    int requestCode,
    @NonNull ActivityResultContract<@NonNull I, @NonNull O> contract,
    @NonNull I input,
    ActivityOptionsCompat options
)
```

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

| Parameters |
|---|---|
| `int requestCode` | request code to use |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/activity/result/contract/ActivityResultContract<@https://developer.android.com/reference/androidx/annotation/NonNull I, @https://developer.android.com/reference/androidx/annotation/NonNull O> contract` | contract to use for type conversions |
| `@https://developer.android.com/reference/androidx/annotation/NonNull I input` | input required to execute an ActivityResultContract. |
| `https://developer.android.com/reference/androidx/core/app/ActivityOptionsCompat options` | 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)

```
public final void onRestoreInstanceState(Bundle savedInstanceState)
```

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

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

### onSaveInstanceState

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

```
public final void onSaveInstanceState(@NonNull Bundle outState)
```

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

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

### register

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

```
public final @NonNull ActivityResultLauncher<@NonNull I> <I extends Object, O extends Object> register(
    @NonNull String key,
    @NonNull ActivityResultContract<@NonNull I, @NonNull O> contract,
    @NonNull ActivityResultCallback<@NonNull O> callback
)
```

Register a new callback with this registry.

This is normally called by a higher level convenience methods like `https://developer.android.com/reference/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/androidx/activity/result/ActivityResultLauncher#unregister()` on the returned `https://developer.android.com/reference/androidx/activity/result/ActivityResultLauncher` when the launcher is no longer needed to release any values that might be captured in the registered callback.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html key` | a unique string key identifying this call |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/activity/result/contract/ActivityResultContract<@https://developer.android.com/reference/androidx/annotation/NonNull I, @https://developer.android.com/reference/androidx/annotation/NonNull O> contract` | the contract specifying input/output types of the call |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/activity/result/ActivityResultCallback<@https://developer.android.com/reference/androidx/annotation/NonNull O> callback` | the activity result callback |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/activity/result/ActivityResultLauncher<@https://developer.android.com/reference/androidx/annotation/NonNull 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)

```
public final @NonNull ActivityResultLauncher<@NonNull I> <I extends Object, O extends Object> register(
    @NonNull String key,
    @NonNull LifecycleOwner lifecycleOwner,
    @NonNull ActivityResultContract<@NonNull I, @NonNull O> contract,
    @NonNull ActivityResultCallback<@NonNull O> callback
)
```

Register a new callback with this registry.

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html key` | a unique string key identifying this call |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner lifecycleOwner` | a `https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner` that makes this call. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/activity/result/contract/ActivityResultContract<@https://developer.android.com/reference/androidx/annotation/NonNull I, @https://developer.android.com/reference/androidx/annotation/NonNull O> contract` | the contract specifying input/output types of the call |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/activity/result/ActivityResultCallback<@https://developer.android.com/reference/androidx/annotation/NonNull O> callback` | the activity result callback |

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