# ActivityEmbeddingController

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

*** ** * ** ***


```
public final class ActivityEmbeddingController
```

<br />

*** ** * ** ***

The controller that allows checking the current `https://developer.android.com/reference/android/app/Activity.html` embedding status.

## Summary

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/embedding/EmbeddedActivityWindowInfo>` | `@https://developer.android.com/reference/androidx/window/RequiresWindowSdkExtension(version = 6) https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController#embeddedActivityWindowInfo(android.app.Activity)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/Activity.html activity)` A `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` of `https://developer.android.com/reference/androidx/window/embedding/EmbeddedActivityWindowInfo` that reports the change to the embedded window related info of the `https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController#embeddedActivityWindowInfo(android.app.Activity)`. |
| `final void` | `@https://developer.android.com/reference/androidx/window/RequiresWindowSdkExtension(version = 5) https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController#finishActivityStacks(kotlin.collections.Set)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/embedding/ActivityStack> activityStacks)` Finishes a set of `https://developer.android.com/reference/androidx/window/embedding/ActivityStack` from the lowest to the highest z-order regardless of the order of `activityStack` passed in the input parameter. |
| `final https://developer.android.com/reference/androidx/window/embedding/ActivityStack` | `https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController#getActivityStack(android.app.Activity)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/Activity.html activity)` Returns the `https://developer.android.com/reference/androidx/window/embedding/ActivityStack` that this `https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController#getActivityStack(android.app.Activity)` is part of when it is being organized in the embedding container and associated with a `https://developer.android.com/reference/androidx/window/embedding/SplitInfo`. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController` | `https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController#getInstance(android.content.Context)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context)` Obtains an instance of `https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController`. |
| `final void` | `@https://developer.android.com/reference/androidx/window/RequiresWindowSdkExtension(version = 3) https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController#invalidateVisibleActivityStacks()()` Triggers calculator functions set through `https://developer.android.com/reference/androidx/window/embedding/SplitController#setSplitAttributesCalculator(kotlin.Function1)` and `https://developer.android.com/reference/androidx/window/embedding/OverlayController#setOverlayAttributesCalculator(kotlin.Function1)` to update attributes for visible `https://developer.android.com/reference/androidx/window/embedding/ActivityStack`. |
| `final boolean` | `https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController#isActivityEmbedded(android.app.Activity)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/Activity.html activity)` Checks if the `https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController#isActivityEmbedded(android.app.Activity)` is embedded and its presentation may be customized by the host process of the task this `https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController#isActivityEmbedded(android.app.Activity)` is associated with. |
| `final void` | `@https://developer.android.com/reference/androidx/window/RequiresWindowSdkExtension(version = 5) https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController#setEmbeddingConfiguration(androidx.window.embedding.EmbeddingConfiguration)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/embedding/EmbeddingConfiguration embeddingConfiguration )` Sets the `https://developer.android.com/reference/androidx/window/embedding/EmbeddingConfiguration` of the Activity Embedding environment that defines how the embedded Activities behaves. |

## Public methods

### embeddedActivityWindowInfo

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

```
@RequiresWindowSdkExtension(version = 6)
public final @NonNull Flow<@NonNull EmbeddedActivityWindowInfo> embeddedActivityWindowInfo(@NonNull Activity activity)
```

A `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` of `https://developer.android.com/reference/androidx/window/embedding/EmbeddedActivityWindowInfo` that reports the change to the embedded window related info of the `https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController#embeddedActivityWindowInfo(android.app.Activity)`.

The `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` will immediately be invoked with the latest value upon registration if the `https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController#embeddedActivityWindowInfo(android.app.Activity)` is currently embedded as `https://developer.android.com/reference/androidx/window/embedding/EmbeddedActivityWindowInfo#isEmbedded()` is `true`.

When the `https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController#embeddedActivityWindowInfo(android.app.Activity)` is embedded, the `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` will be invoked when `https://developer.android.com/reference/androidx/window/embedding/EmbeddedActivityWindowInfo` is changed. When the `https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController#embeddedActivityWindowInfo(android.app.Activity)` is not embedded, the `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` will not be triggered unless the `https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController#embeddedActivityWindowInfo(android.app.Activity)` is becoming non-embedded from embedded.

Note that this API is only supported on the device with `https://developer.android.com/reference/androidx/window/WindowSdkExtensions#extensionVersion()` equal to or larger than 6. If `https://developer.android.com/reference/androidx/window/WindowSdkExtensions#extensionVersion()` is less than 6, this `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` will not be invoked.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/Activity.html activity` | the `https://developer.android.com/reference/android/app/Activity.html` that is interested in getting the embedded window info. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/embedding/EmbeddedActivityWindowInfo>` | a `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` of `https://developer.android.com/reference/androidx/window/embedding/EmbeddedActivityWindowInfo` of the `https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController#embeddedActivityWindowInfo(android.app.Activity)`. |

### finishActivityStacks

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

```
@RequiresWindowSdkExtension(version = 5)
public final void finishActivityStacks(@NonNull Set<@NonNull ActivityStack> activityStacks)
```

Finishes a set of `https://developer.android.com/reference/androidx/window/embedding/ActivityStack` from the lowest to the highest z-order regardless of the order of `activityStack` passed in the input parameter.

If a remaining activityStack from a split participates in other splits with other activityStacks, the remaining activityStack might split with other activityStacks. For example, if activityStack A splits with activityStack B and C, and activityStack C covers activityStack B, finishing activityStack C might make the split of activityStack A and B show.

If all split-associated activityStacks are finished, the remaining activityStack will be expanded to fill the parent task container. This is useful to expand the primary container as the sample linked below shows.

**Note** that it's caller's responsibility to check whether this API is supported by checking `https://developer.android.com/reference/androidx/window/WindowSdkExtensions#extensionVersion()` is greater than or equal to 5. If not, an alternative approach to finishing all containers above a particular activity can be to launch it again with flag `https://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP`.

```kotlin
import androidx.window.embedding.ActivityEmbeddingController
import androidx.window.embedding.SplitController

SplitController.getInstance(primaryActivity).splitInfoList(primaryActivity).collect {
    splitInfoList ->
    // Find all associated secondary ActivityStacks
    val associatedSecondaryActivityStacks =
        splitInfoList.mapTo(mutableSetOf()) { splitInfo -> splitInfo.secondaryActivityStack }
    // Finish them all.
    ActivityEmbeddingController.getInstance(primaryActivity)
        .finishActivityStacks(associatedSecondaryActivityStacks)
}
```

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/embedding/ActivityStack> activityStacks` | The set of `https://developer.android.com/reference/androidx/window/embedding/ActivityStack` to be finished. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` | if extension version is less than 5. |

### getActivityStack

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

```
public final ActivityStack getActivityStack(@NonNull Activity activity)
```

Returns the `https://developer.android.com/reference/androidx/window/embedding/ActivityStack` that this `https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController#getActivityStack(android.app.Activity)` is part of when it is being organized in the embedding container and associated with a `https://developer.android.com/reference/androidx/window/embedding/SplitInfo`. Returns `null` if there is no such `https://developer.android.com/reference/androidx/window/embedding/ActivityStack`.

Started from `https://developer.android.com/reference/androidx/window/WindowSdkExtensions#extensionVersion()` 5, this method can also obtain standalone `https://developer.android.com/reference/androidx/window/embedding/ActivityStack`, which is not associated with any `https://developer.android.com/reference/androidx/window/embedding/SplitInfo`. For example, an `https://developer.android.com/reference/androidx/window/embedding/ActivityStack` launched with `https://developer.android.com/reference/androidx/window/embedding/ActivityRule#alwaysExpand()`, or an overlay `https://developer.android.com/reference/androidx/window/embedding/ActivityStack` launched by `https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController#setLaunchingActivityStack(android.os.Bundle,androidx.window.embedding.ActivityStack)` with `https://developer.android.com/reference/androidx/window/embedding/OverlayCreateParams`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/Activity.html activity` | The `https://developer.android.com/reference/android/app/Activity.html` to check. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/window/embedding/ActivityStack` | the `https://developer.android.com/reference/androidx/window/embedding/ActivityStack` that this `https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController#getActivityStack(android.app.Activity)` is part of, or `null` if there is no such `https://developer.android.com/reference/androidx/window/embedding/ActivityStack`. |

### getInstance

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

```
public static final @NonNull ActivityEmbeddingController getInstance(@NonNull Context context)
```

Obtains an instance of `https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController`.

| 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` to initialize the controller with |

### invalidateVisibleActivityStacks

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

```
@RequiresWindowSdkExtension(version = 3)
public final void invalidateVisibleActivityStacks()
```

Triggers calculator functions set through `https://developer.android.com/reference/androidx/window/embedding/SplitController#setSplitAttributesCalculator(kotlin.Function1)` and `https://developer.android.com/reference/androidx/window/embedding/OverlayController#setOverlayAttributesCalculator(kotlin.Function1)` to update attributes for visible `https://developer.android.com/reference/androidx/window/embedding/ActivityStack`.

This method can be used when the application wants to update the embedding presentation based on the application state.

This method is not needed for changes that are driven by window and device state changes or new activity starts, because those will invoke the calculator functions automatically.

Visible `https://developer.android.com/reference/androidx/window/embedding/ActivityStack` are usually the last element of `https://developer.android.com/reference/androidx/window/embedding/SplitInfo` list which was received from the callback registered in `https://developer.android.com/reference/androidx/window/embedding/SplitController#splitInfoList(android.app.Activity)` and an active overlay `https://developer.android.com/reference/androidx/window/embedding/ActivityStack` if exists.

The call will be no-op if there is no visible `https://developer.android.com/reference/androidx/window/embedding/ActivityStack` or there's no calculator set.

| 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 3. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/window/embedding/OverlayController#setOverlayAttributesCalculator(kotlin.Function1)` |   |
| `https://developer.android.com/reference/androidx/window/embedding/SplitController#setSplitAttributesCalculator(kotlin.Function1)` |   |

### isActivityEmbedded

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

```
public final boolean isActivityEmbedded(@NonNull Activity activity)
```

Checks if the `https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController#isActivityEmbedded(android.app.Activity)` is embedded and its presentation may be customized by the host process of the task this `https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController#isActivityEmbedded(android.app.Activity)` is associated with.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/Activity.html activity` | the `https://developer.android.com/reference/android/app/Activity.html` to check. |

### setEmbeddingConfiguration

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

```
@RequiresWindowSdkExtension(version = 5)
public final void setEmbeddingConfiguration(
    @NonNull EmbeddingConfiguration embeddingConfiguration
)
```

Sets the `https://developer.android.com/reference/androidx/window/embedding/EmbeddingConfiguration` of the Activity Embedding environment that defines how the embedded Activities behaves.

The `https://developer.android.com/reference/androidx/window/embedding/EmbeddingConfiguration` can be supported only if the vendor API level of the target device is equals or higher than required API level. Otherwise, it would be no-op when setting the `https://developer.android.com/reference/androidx/window/embedding/EmbeddingConfiguration` on a target device that has lower API level.

In addition, the existing configuration in the library won't be overwritten if the properties of the given `https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController#setEmbeddingConfiguration(androidx.window.embedding.EmbeddingConfiguration)` are undefined. Only the configuration properties that are explicitly set will be updated.

**Note** that it is recommended to be configured in the `https://developer.android.com/reference/androidx/startup/Initializer` or `https://developer.android.com/reference/android/app/Application.html#onCreate()`, so that the `https://developer.android.com/reference/androidx/window/embedding/EmbeddingConfiguration` is applied early in the application startup, before any activities complete initialization. The `https://developer.android.com/reference/androidx/window/embedding/EmbeddingConfiguration` updates afterward may or may not apply to already running activities.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/embedding/EmbeddingConfiguration embeddingConfiguration` | The `https://developer.android.com/reference/androidx/window/embedding/EmbeddingConfiguration` |