# ActivityScenarioKt

*** ** * ** ***


```
public final class ActivityScenarioKt
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/core/app/ActivityScenario<@https://developer.android.com/reference/androidx/annotation/NonNull A>` | `<A extends https://developer.android.com/reference/android/app/Activity.html> https://developer.android.com/reference/androidx/test/core/app/ActivityScenarioKt#launchActivity(android.content.Intent,android.os.Bundle)(https://developer.android.com/reference/android/content/Intent.html intent, https://developer.android.com/reference/android/os/Bundle.html activityOptions)` Launches an activity of a given class and constructs ActivityScenario with the activity. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/core/app/ActivityScenario<@https://developer.android.com/reference/androidx/annotation/NonNull A>` | `<A extends https://developer.android.com/reference/android/app/Activity.html> https://developer.android.com/reference/androidx/test/core/app/ActivityScenarioKt#launchActivityForResult(android.content.Intent,android.os.Bundle)( https://developer.android.com/reference/android/content/Intent.html intent, https://developer.android.com/reference/android/os/Bundle.html activityOptions )` Launches an activity of a given class and constructs ActivityScenario with the activity. |

## Public methods

### launchActivity

Artifact: [androidx.test:core-ktx](https://developer.android.com/jetpack/androidx/releases/test) [View Source](https://cs.android.com/search?q=file:androidx/test/core/app/ActivityScenario.kt+function:launchActivity)

```
public static final @NonNull ActivityScenario<@NonNull A> <A extends Activity> launchActivity(Intent intent, Bundle activityOptions)
```

Launches an activity of a given class and constructs ActivityScenario with the activity. Waits for the lifecycle state transitions to be complete.

Normally this would be `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State#RESUMED`, but may be another state.

This method cannot be called from the main thread except in Robolectric tests.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Intent.html intent` | an intent to start activity or null to use the default one |
| `https://developer.android.com/reference/android/os/Bundle.html activityOptions` | an activity options bundle to be passed along with the intent to start activity |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/core/app/ActivityScenario<@https://developer.android.com/reference/androidx/annotation/NonNull A>` | ActivityScenario which you can use to make further state transitions |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-assertion-error/index.html` | if the lifecycle state transition never completes within the timeout |

### launchActivityForResult

Artifact: [androidx.test:core-ktx](https://developer.android.com/jetpack/androidx/releases/test) [View Source](https://cs.android.com/search?q=file:androidx/test/core/app/ActivityScenario.kt+function:launchActivityForResult)

```
public static final @NonNull ActivityScenario<@NonNull A> <A extends Activity> launchActivityForResult(
    Intent intent,
    Bundle activityOptions
)
```

Launches an activity of a given class and constructs ActivityScenario with the activity. Waits for the lifecycle state transitions to be complete. Broadcasts activity result.

Normally this would be `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State#RESUMED`, but may be another state.

This method cannot be called from the main thread except in Robolectric tests.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Intent.html intent` | an intent to start activity or null to use the default one |
| `https://developer.android.com/reference/android/os/Bundle.html activityOptions` | an activity options bundle to be passed along with the intent to start activity |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/core/app/ActivityScenario<@https://developer.android.com/reference/androidx/annotation/NonNull A>` | ActivityScenario which you can use to make further state transitions |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-assertion-error/index.html` | if the lifecycle state transition never completes within the timeout |