# ActivityEmbeddingOptions

Added in 1.4.0

*** ** * ** ***


```
public final class ActivityEmbeddingOptions
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/Bundle.html` | `@https://developer.android.com/reference/androidx/window/RequiresWindowSdkExtension(version = 5) https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingOptions#(android.os.Bundle).setLaunchingActivityStack(android.content.Context,androidx.window.embedding.ActivityStack)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/Bundle.html receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/embedding/ActivityStack activityStack )` Sets the target launching `https://developer.android.com/reference/androidx/window/embedding/ActivityStack` to the given `https://developer.android.com/reference/android/os/Bundle.html`. |

## Public methods

### setLaunchingActivityStack

Artifact: [androidx.window:window](https://developer.android.com/jetpack/androidx/releases/window) [View Source](https://cs.android.com/search?q=file:androidx/window/embedding/ActivityEmbeddingOptions.kt+function:setLaunchingActivityStack) Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/window#1.4.0)

```
@RequiresWindowSdkExtension(version = 5)
public static final @NonNull Bundle setLaunchingActivityStack(
    @NonNull Bundle receiver,
    @NonNull Context context,
    @NonNull ActivityStack activityStack
)
```

Sets the target launching `https://developer.android.com/reference/androidx/window/embedding/ActivityStack` to the given `https://developer.android.com/reference/android/os/Bundle.html`.

The `https://developer.android.com/reference/android/os/Bundle.html` then could be used to launch an `https://developer.android.com/reference/android/app/Activity.html` to the top of the `https://developer.android.com/reference/androidx/window/embedding/ActivityStack` through `https://developer.android.com/reference/android/app/Activity.html#startActivity(android.content.Intent)`. If there's a bundle used for customizing how the `https://developer.android.com/reference/android/app/Activity.html` should be started by `https://developer.android.com/reference/android/app/ActivityOptions.html#toBundle()` or `https://developer.android.com/reference/androidx/core/app/ActivityOptionsCompat#toBundle()`, it's suggested to use the bundle to call this method.

It is suggested to use a visible `https://developer.android.com/reference/androidx/window/embedding/ActivityStack` reported by `https://developer.android.com/reference/androidx/window/embedding/SplitController#splitInfoList(android.app.Activity)` or `https://developer.android.com/reference/androidx/window/embedding/OverlayController#overlayInfo(kotlin.String)`, or the launching activity will be launched on the default target if the `https://developer.android.com/reference/androidx/window/embedding/package-summary#(android.os.Bundle).setLaunchingActivityStack(android.content.Context,androidx.window.embedding.ActivityStack)` no longer exists in the host task. The default target could be the top of the visible split's secondary `https://developer.android.com/reference/androidx/window/embedding/ActivityStack`, or the top of the host task.

Below samples are use cases to specify the launching `https://developer.android.com/reference/androidx/window/embedding/ActivityStack`.

```kotlin
import androidx.core.app.ActivityOptionsCompat
import androidx.window.embedding.ActivityStack
import androidx.window.embedding.SplitController
import androidx.window.embedding.setLaunchingActivityStack

var primaryActivityStack: ActivityStack? = null

SplitController.getInstance(primaryActivity).splitInfoList(primaryActivity).collect {
    splitInfoList ->
    primaryActivityStack = splitInfoList.last().primaryActivityStack
}

primaryActivity.startActivity(
    INTENT,
    ActivityOptionsCompat.makeBasic()
        .toBundle()!!
        .setLaunchingActivityStack(primaryActivity, primaryActivityStack!!),
)
```

```kotlin
import androidx.core.app.ActivityOptionsCompat
import androidx.window.embedding.ActivityStack
import androidx.window.embedding.OverlayController
import androidx.window.embedding.setLaunchingActivityStack

var overlayActivityStack: ActivityStack? = null

OverlayController.getInstance(context).overlayInfo(TAG_OVERLAY).collect { overlayInfo ->
    overlayActivityStack = overlayInfo.activityStack
}

// The use case is to launch an Activity to an existing overlay ActivityStack from the overlain
// Activity. If activityStack is not specified, the activity is launched to the top of the
// host task behind the overlay ActivityStack.
overlainActivity.startActivity(
    INTENT,
    ActivityOptionsCompat.makeBasic()
        .toBundle()!!
        .setLaunchingActivityStack(overlainActivity, overlayActivityStack!!),
)
```

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | The `https://developer.android.com/reference/android/content/Context.html` that is going to be used for launching activity with this `https://developer.android.com/reference/android/os/Bundle.html`, which is usually be the `https://developer.android.com/reference/android/app/Activity.html` of the app that hosts the task. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/embedding/ActivityStack activityStack` | The target `https://developer.android.com/reference/androidx/window/embedding/ActivityStack` for launching. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` | if `https://developer.android.com/reference/androidx/window/WindowSdkExtensions#extensionVersion()` is less than 5. |