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

*** ** * ** ***


```
public 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 methods |
|---|---|
| `abstract void` | `https://developer.android.com/reference/androidx/window/area/WindowAreaController#addWindowAreasListener(java.util.concurrent.Executor,androidx.core.util.Consumer)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/util/Consumer<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/area/WindowArea>> listener )` Registers a listener that is interested in the current list of `https://developer.android.com/reference/androidx/window/area/WindowArea` available to be interacted with. |
| `abstract https://developer.android.com/reference/androidx/window/area/WindowAreaSessionPresenter` | `@https://developer.android.com/reference/androidx/window/core/ExperimentalWindowApi https://developer.android.com/reference/androidx/window/area/WindowAreaController#getActivePresentationSession(androidx.window.area.WindowAreaToken)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/area/WindowAreaToken windowAreaToken)` Returns the current active `https://developer.android.com/reference/androidx/window/area/WindowAreaSessionPresenter` if one is currently active in the `https://developer.android.com/reference/androidx/window/area/WindowArea` identified by the provided `https://developer.android.com/reference/androidx/window/area/WindowAreaToken`. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/area/WindowAreaController` | `https://developer.android.com/reference/androidx/window/area/WindowAreaController#getOrCreate()()` Provides an instance of `https://developer.android.com/reference/androidx/window/area/WindowAreaController`. |
| `abstract void` | `@https://developer.android.com/reference/androidx/window/core/ExperimentalWindowApi https://developer.android.com/reference/androidx/window/area/WindowAreaController#presentContentOnWindowArea(androidx.window.area.WindowAreaToken,android.app.Activity,java.util.concurrent.Executor,androidx.window.area.WindowAreaPresentationSessionCallback)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/area/WindowAreaToken windowAreaToken, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/Activity.html activity, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/area/WindowAreaPresentationSessionCallback windowAreaPresentationSessionCallback )` Starts a presentation session on the `https://developer.android.com/reference/androidx/window/area/WindowArea` identified by the `https://developer.android.com/reference/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/androidx/window/area/WindowAreaPresentationSessionCallback`. |
| `abstract void` | `https://developer.android.com/reference/androidx/window/area/WindowAreaController#removeWindowAreasListener(androidx.core.util.Consumer)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/util/Consumer<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/area/WindowArea>> listener )` Removes a listener of available `https://developer.android.com/reference/androidx/window/area/WindowArea` records. |
| `abstract void` | `https://developer.android.com/reference/androidx/window/area/WindowAreaController#transferToWindowArea(androidx.window.area.WindowAreaToken,android.app.Activity)( https://developer.android.com/reference/androidx/window/area/WindowAreaToken windowAreaToken, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/Activity.html activity )` 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/androidx/window/area/WindowArea` provided. |

## Public methods

### addWindowAreasListener

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

```
public abstract void addWindowAreasListener(
    @NonNull Executor executor,
    @NonNull Consumer<@NonNull List<@NonNull WindowArea>> listener
)
```

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

The `https://developer.android.com/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | to handle sending listener updates. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/util/Consumer<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/area/WindowArea>> listener` | to receive updates to the list of `https://developer.android.com/reference/androidx/window/area/WindowArea`. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/window/area/WindowAreaController#transferToWindowArea(androidx.window.area.WindowAreaToken,android.app.Activity)` |   |
| `https://developer.android.com/reference/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
public abstract WindowAreaSessionPresenter getActivePresentationSession(@NonNull WindowAreaToken windowAreaToken)
```

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

### getOrCreate

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

```
public static final @NonNull WindowAreaController getOrCreate()
```

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

### presentContentOnWindowArea

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

```
@ExperimentalWindowApi
public abstract void presentContentOnWindowArea(
    @NonNull WindowAreaToken windowAreaToken,
    @NonNull Activity activity,
    @NonNull Executor executor,
    @NonNull WindowAreaPresentationSessionCallback windowAreaPresentationSessionCallback
)
```

Starts a presentation session on the `https://developer.android.com/reference/androidx/window/area/WindowArea` identified by the `https://developer.android.com/reference/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/androidx/window/area/WindowAreaPresentationSessionCallback`.

If a presentation session is attempted to be started without it being available, `https://developer.android.com/reference/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/androidx/window/area/WindowAreaPresentationSessionCallback#onSessionStarted(androidx.window.area.WindowAreaSessionPresenter)` is closed. The `https://developer.android.com/reference/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/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/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/area/WindowAreaToken windowAreaToken` | identifier for which `https://developer.android.com/reference/androidx/window/area/WindowArea` is to be presented on |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/Activity.html activity` | An `https://developer.android.com/reference/android/app/Activity.html` that will present content on the Rear Display. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | Executor used to provide updates to `https://developer.android.com/reference/androidx/window/area/WindowAreaController#presentContentOnWindowArea(androidx.window.area.WindowAreaToken,android.app.Activity,java.util.concurrent.Executor,androidx.window.area.WindowAreaPresentationSessionCallback)`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/area/WindowAreaPresentationSessionCallback windowAreaPresentationSessionCallback` | to be notified of updates to the lifecycle of the currently enabled rear display presentation. |

| See also |
|---|---|
| `https://developer.android.com/reference/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)

```
public abstract void removeWindowAreasListener(
    @NonNull Consumer<@NonNull List<@NonNull WindowArea>> listener
)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/util/Consumer<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/window/area/WindowArea>> listener` | to remove from receiving status updates. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/window/area/WindowAreaController#transferToWindowArea(androidx.window.area.WindowAreaToken,android.app.Activity)` |   |
| `https://developer.android.com/reference/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)

```
public abstract void transferToWindowArea(
    WindowAreaToken windowAreaToken,
    @NonNull Activity activity
)
```

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/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/androidx/window/area/WindowAreaController#addWindowAreasListener(java.util.concurrent.Executor,androidx.core.util.Consumer)` and then querying for the `https://developer.android.com/reference/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/androidx/window/area/WindowArea` does not return `https://developer.android.com/reference/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/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/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/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/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/androidx/window/area/WindowAreaCapability.Status#WINDOW_AREA_STATUS_ACTIVE()`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/window/area/WindowAreaToken windowAreaToken` | `https://developer.android.com/reference/androidx/window/area/WindowAreaToken` window area token that identifies the `https://developer.android.com/reference/androidx/window/area/WindowArea` to move to. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/Activity.html activity` | Base Activity making the call to `https://developer.android.com/reference/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/androidx/window/area/WindowArea` does not have a `https://developer.android.com/reference/androidx/window/area/WindowAreaCapability.Status#WINDOW_AREA_STATUS_AVAILABLE()` status for `https://developer.android.com/reference/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/androidx/window/area/WindowArea` with a `https://developer.android.com/reference/androidx/window/area/WindowArea.Type` that is unrecognized. |

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