# ActivityEmbeddingController

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

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/window/embedding/ActivityEmbeddingController "View this page in Java")

<br />

```
class ActivityEmbeddingController
```

<br />

*** ** * ** ***

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

## Summary

|                                                   ### Public companion functions                                                    |
|-------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ActivityEmbeddingController](https://developer.android.com/reference/kotlin/androidx/window/embedding/ActivityEmbeddingController) | [getInstance](https://developer.android.com/reference/kotlin/androidx/window/embedding/ActivityEmbeddingController#getInstance(android.content.Context))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`)` Obtains an instance of[ActivityEmbeddingController](https://developer.android.com/reference/kotlin/androidx/window/embedding/ActivityEmbeddingController). |

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

## Public companion functions

### getInstance

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

```
fun getInstance(context: Context): ActivityEmbeddingController
```

Obtains an instance of[ActivityEmbeddingController](https://developer.android.com/reference/kotlin/androidx/window/embedding/ActivityEmbeddingController).  

|                                         Parameters                                         |
|--------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html) | the[Context](https://developer.android.com/reference/android/content/Context.html)to initialize the controller with |

## Public functions

### embeddedActivityWindowInfo

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

```
@RequiresWindowSdkExtension(version = 6)
fun embeddedActivityWindowInfo(activity: Activity): Flow<EmbeddedActivityWindowInfo>
```

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

The[Flow](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[activity](https://developer.android.com/reference/kotlin/androidx/window/embedding/ActivityEmbeddingController#embeddedActivityWindowInfo(android.app.Activity))is currently embedded as[EmbeddedActivityWindowInfo.isEmbedded](https://developer.android.com/reference/kotlin/androidx/window/embedding/EmbeddedActivityWindowInfo#isEmbedded())is`true`.

When the[activity](https://developer.android.com/reference/kotlin/androidx/window/embedding/ActivityEmbeddingController#embeddedActivityWindowInfo(android.app.Activity))is embedded, the[Flow](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html)will be invoked when[EmbeddedActivityWindowInfo](https://developer.android.com/reference/kotlin/androidx/window/embedding/EmbeddedActivityWindowInfo)is changed. When the[activity](https://developer.android.com/reference/kotlin/androidx/window/embedding/ActivityEmbeddingController#embeddedActivityWindowInfo(android.app.Activity))is not embedded, the[Flow](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html)will not be triggered unless the[activity](https://developer.android.com/reference/kotlin/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[WindowSdkExtensions.extensionVersion](https://developer.android.com/reference/kotlin/androidx/window/WindowSdkExtensions#extensionVersion())equal to or larger than 6. If[WindowSdkExtensions.extensionVersion](https://developer.android.com/reference/kotlin/androidx/window/WindowSdkExtensions#extensionVersion())is less than 6, this[Flow](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html)will not be invoked.  

|                                        Parameters                                         |
|-------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|
| `activity: `[Activity](https://developer.android.com/reference/android/app/Activity.html) | the[Activity](https://developer.android.com/reference/android/app/Activity.html)that is interested in getting the embedded window info. |

|                                                                                                                            Returns                                                                                                                            |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Flow](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html)`<`[EmbeddedActivityWindowInfo](https://developer.android.com/reference/kotlin/androidx/window/embedding/EmbeddedActivityWindowInfo)`>` | a[Flow](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html)of[EmbeddedActivityWindowInfo](https://developer.android.com/reference/kotlin/androidx/window/embedding/EmbeddedActivityWindowInfo)of the[activity](https://developer.android.com/reference/kotlin/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)
fun finishActivityStacks(activityStacks: Set<ActivityStack>): Unit
```

Finishes a set of[activityStacks](https://developer.android.com/reference/kotlin/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[WindowSdkExtensions.extensionVersion](https://developer.android.com/reference/kotlin/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[android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP](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                                                                                                       |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|
| `activityStacks: `[Set](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html)`<`[ActivityStack](https://developer.android.com/reference/kotlin/androidx/window/embedding/ActivityStack)`>` | The set of[ActivityStack](https://developer.android.com/reference/kotlin/androidx/window/embedding/ActivityStack)to be finished. |

|                                                                  Throws                                                                  |
|------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------|
| [kotlin.UnsupportedOperationException](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)  

```
fun getActivityStack(activity: Activity): ActivityStack?
```

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

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

|                                        Parameters                                         |
|-------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------|
| `activity: `[Activity](https://developer.android.com/reference/android/app/Activity.html) | The[Activity](https://developer.android.com/reference/android/app/Activity.html)to check. |

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

### invalidateVisibleActivityStacks

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

```
@RequiresWindowSdkExtension(version = 3)
fun invalidateVisibleActivityStacks(): Unit
```

Triggers calculator functions set through[SplitController.setSplitAttributesCalculator](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitController#setSplitAttributesCalculator(kotlin.Function1))and[OverlayController.setOverlayAttributesCalculator](https://developer.android.com/reference/kotlin/androidx/window/embedding/OverlayController#setOverlayAttributesCalculator(kotlin.Function1))to update attributes for visible[activityStacks](https://developer.android.com/reference/kotlin/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[activityStacks](https://developer.android.com/reference/kotlin/androidx/window/embedding/ActivityStack)are usually the last element of[SplitInfo](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitInfo)list which was received from the callback registered in[SplitController.splitInfoList](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitController#splitInfoList(android.app.Activity))and an active overlay[ActivityStack](https://developer.android.com/reference/kotlin/androidx/window/embedding/ActivityStack)if exists.

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

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

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

### isActivityEmbedded

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

```
fun isActivityEmbedded(activity: Activity): Boolean
```

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

|                                        Parameters                                         |
|-------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------|
| `activity: `[Activity](https://developer.android.com/reference/android/app/Activity.html) | the[Activity](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)
fun setEmbeddingConfiguration(
    embeddingConfiguration: EmbeddingConfiguration
): Unit
```

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

The[EmbeddingConfiguration](https://developer.android.com/reference/kotlin/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[EmbeddingConfiguration](https://developer.android.com/reference/kotlin/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[embeddingConfiguration](https://developer.android.com/reference/kotlin/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[androidx.startup.Initializer](https://developer.android.com/reference/kotlin/androidx/startup/Initializer)or[android.app.Application.onCreate](https://developer.android.com/reference/android/app/Application.html#onCreate()), so that the[EmbeddingConfiguration](https://developer.android.com/reference/kotlin/androidx/window/embedding/EmbeddingConfiguration)is applied early in the application startup, before any activities complete initialization. The[EmbeddingConfiguration](https://developer.android.com/reference/kotlin/androidx/window/embedding/EmbeddingConfiguration)updates afterward may or may not apply to already running activities.  

|                                                                     Parameters                                                                      |
|-----------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
| `embeddingConfiguration: `[EmbeddingConfiguration](https://developer.android.com/reference/kotlin/androidx/window/embedding/EmbeddingConfiguration) | The[EmbeddingConfiguration](https://developer.android.com/reference/kotlin/androidx/window/embedding/EmbeddingConfiguration) |