# WindowAreaController

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

*** ** * ** ***


```
abstract class WindowAreaController
```

<br />

*** ** * ** ***

An interface to provide the information and behavior around moving windows between displays or display areas on a device.

## Summary

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaController` | `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaController#getOrCreate()()` Provides an instance of `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaController`. |

| ### Public functions |
|---|---|
| `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaController#addWindowAreasListener(java.util.concurrent.Executor,androidx.core.util.Consumer)( executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, listener: https://developer.android.com/reference/kotlin/androidx/core/util/Consumer<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea>> )` Registers a listener that is interested in the current list of `https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea` available to be interacted with. |
| `abstract https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaSessionPresenter?` | `@https://developer.android.com/reference/kotlin/androidx/window/core/ExperimentalWindowApi https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaController#getActivePresentationSession(androidx.window.area.WindowAreaToken)(windowAreaToken: https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaToken)` Returns the current active `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaSessionPresenter` if one is currently active in the `https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea` identified by the provided `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaToken`. |
| `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/window/core/ExperimentalWindowApi https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaController#presentContentOnWindowArea(androidx.window.area.WindowAreaToken,android.app.Activity,java.util.concurrent.Executor,androidx.window.area.WindowAreaPresentationSessionCallback)( windowAreaToken: https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaToken, activity: https://developer.android.com/reference/android/app/Activity.html, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, windowAreaPresentationSessionCallback: https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaPresentationSessionCallback )` Starts a presentation session on the `https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea` identified by the `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaController#presentContentOnWindowArea(androidx.window.area.WindowAreaToken,android.app.Activity,java.util.concurrent.Executor,androidx.window.area.WindowAreaPresentationSessionCallback)` and sends updates through the `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaPresentationSessionCallback`. |
| `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaController#removeWindowAreasListener(androidx.core.util.Consumer)(listener: https://developer.android.com/reference/kotlin/androidx/core/util/Consumer<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea>>)` Removes a listener of available `https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea` records. |
| `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaController#transferToWindowArea(androidx.window.area.WindowAreaToken,android.app.Activity)( windowAreaToken: https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaToken?, activity: https://developer.android.com/reference/android/app/Activity.html )` Moves the calling `https://developer.android.com/reference/android/app/Activity.html` and the global state of the device to the `https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea` provided. |

## Public companion functions

### getOrCreate

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

```
fun getOrCreate(): WindowAreaController
```

Provides an instance of `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaController`.

## Public functions

### addWindowAreasListener

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

```
abstract fun addWindowAreasListener(
    executor: Executor,
    listener: Consumer<List<WindowArea>>
): Unit
```

Registers a listener that is interested in the current list of `https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea` available to be interacted with.

The `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaController#addWindowAreasListener(java.util.concurrent.Executor,androidx.core.util.Consumer)` will receive an initial value on registration, as soon as it becomes available.

| Parameters |
|---|---|
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | to handle sending listener updates. |
| `listener: https://developer.android.com/reference/kotlin/androidx/core/util/Consumer<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea>>` | to receive updates to the list of `https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea`. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaController#transferToWindowArea(androidx.window.area.WindowAreaToken,android.app.Activity)` |   |
| `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaController#presentContentOnWindowArea(androidx.window.area.WindowAreaToken,android.app.Activity,java.util.concurrent.Executor,androidx.window.area.WindowAreaPresentationSessionCallback)` |   |

### getActivePresentationSession

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

```
@ExperimentalWindowApi
abstract fun getActivePresentationSession(windowAreaToken: WindowAreaToken): WindowAreaSessionPresenter?
```

Returns the current active `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaSessionPresenter` if one is currently active in the `https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea` identified by the provided `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaToken`. Returns null if there is no active presentation session for the provided `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaController#getActivePresentationSession(androidx.window.area.WindowAreaToken)`.

### presentContentOnWindowArea

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

```
@ExperimentalWindowApi
abstract fun presentContentOnWindowArea(
    windowAreaToken: WindowAreaToken,
    activity: Activity,
    executor: Executor,
    windowAreaPresentationSessionCallback: WindowAreaPresentationSessionCallback
): Unit
```

Starts a presentation session on the `https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea` identified by the `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaController#presentContentOnWindowArea(androidx.window.area.WindowAreaToken,android.app.Activity,java.util.concurrent.Executor,androidx.window.area.WindowAreaPresentationSessionCallback)` and sends updates through the `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaPresentationSessionCallback`.

If a presentation session is attempted to be started without it being available, `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaPresentationSessionCallback#onSessionEnded(kotlin.Throwable)` will be called immediately with an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html`.

Only the top visible application can request to start a presentation session.

The presentation session will stay active until the presentation provided through `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaPresentationSessionCallback#onSessionStarted(androidx.window.area.WindowAreaSessionPresenter)` is closed. The `https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea.Type` may provide different triggers to close the session such as if the calling application is no longer in the foreground, or there is a device state change that makes the window area unavailable to be presented on. One example scenario is if a `https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea.Type#TYPE_REAR_FACING()` window area is being presented to on a foldable device that is open and has 2 screens. If the device is closed and the internal display is turned off, the session would be ended and `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaPresentationSessionCallback#onSessionEnded(kotlin.Throwable)` is called to notify that the session has been ended. The session may end prematurely if the device gets to a critical thermal level, or if power saver mode is enabled.

| Parameters |
|---|---|
| `windowAreaToken: https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaToken` | identifier for which `https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea` is to be presented on |
| `activity: https://developer.android.com/reference/android/app/Activity.html` | An `https://developer.android.com/reference/android/app/Activity.html` that will present content on the Rear Display. |
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | Executor used to provide updates to `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaController#presentContentOnWindowArea(androidx.window.area.WindowAreaToken,android.app.Activity,java.util.concurrent.Executor,androidx.window.area.WindowAreaPresentationSessionCallback)`. |
| `windowAreaPresentationSessionCallback: https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaPresentationSessionCallback` | to be notified of updates to the lifecycle of the currently enabled rear display presentation. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaController#addWindowAreasListener(java.util.concurrent.Executor,androidx.core.util.Consumer)` |   |

### removeWindowAreasListener

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

```
abstract fun removeWindowAreasListener(listener: Consumer<List<WindowArea>>): Unit
```

Removes a listener of available `https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea` records. If the listener is not present then this method is a no-op.

| Parameters |
|---|---|
| `listener: https://developer.android.com/reference/kotlin/androidx/core/util/Consumer<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea>>` | to remove from receiving status updates. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaController#transferToWindowArea(androidx.window.area.WindowAreaToken,android.app.Activity)` |   |
| `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaController#presentContentOnWindowArea(androidx.window.area.WindowAreaToken,android.app.Activity,java.util.concurrent.Executor,androidx.window.area.WindowAreaPresentationSessionCallback)` |   |

### transferToWindowArea

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

```
abstract fun transferToWindowArea(
    windowAreaToken: WindowAreaToken?,
    activity: Activity
): Unit
```

Moves the calling `https://developer.android.com/reference/android/app/Activity.html` and the global state of the device to the `https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea` provided. This is a long-lasting and sticky operation that will outlive the application that requests this operation. Status updates can be received from the value received by registering a listener through `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaController#addWindowAreasListener(java.util.concurrent.Executor,androidx.core.util.Consumer)` and then querying for the `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaCapability.Operation#OPERATION_TRANSFER_TO_AREA()` operation.

Attempting to move the device to a window area when the `https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea` does not return `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaCapability.Status#WINDOW_AREA_STATUS_AVAILABLE()` will result in an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html`.

Only the top visible application can request the device ot move to a `https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea`. If this operation is requested when the application is not the top level process, a `https://developer.android.com/reference/java/lang/SecurityException.html` will be thrown.

Passing a null `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaToken` returns back to the default window area (usually going to be the `https://developer.android.com/reference/android/view/Display.html#DEFAULT_DISPLAY`). Depending on the `https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea.Type` there may be other triggers that end the session, such as if a device state change makes the window area =unavailable. One example of this is if the device is currently moved to the `https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea.Type#TYPE_REAR_FACING()` window area of a foldable device, the device will be moved back to the default window area, and the status of the operation will no longer be `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaCapability.Status#WINDOW_AREA_STATUS_ACTIVE()`.

| Parameters |
|---|---|
| `windowAreaToken: https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaToken?` | `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaToken` window area token that identifies the `https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea` to move to. |
| `activity: https://developer.android.com/reference/android/app/Activity.html` | Base Activity making the call to `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaController#transferToWindowArea(androidx.window.area.WindowAreaToken,android.app.Activity)`. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if this method is called when the provided `https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea` does not have a `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaCapability.Status#WINDOW_AREA_STATUS_AVAILABLE()` status for `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaCapability.Operation#OPERATION_TRANSFER_TO_AREA()`. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | if this method is called from a process that is not the top-level process. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if this method is called with a `https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea` with a `https://developer.android.com/reference/kotlin/androidx/window/area/WindowArea.Type` that is unrecognized. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/window/area/WindowAreaController#addWindowAreasListener(java.util.concurrent.Executor,androidx.core.util.Consumer)` |   |