The second Android 11 Developer Preview is now available, test it out and share your feedback.

WindowBackend

interface WindowBackend
androidx.window.WindowBackend

Backing interface for WindowManager instances that server as the default information supplier. By default ExtensionWindowBackend implementation is used in WindowManager#WindowManager(Context, WindowBackend), but it can be replaced with a stub for testing.

Summary

Public methods

abstract DeviceState

Get the current device state.

abstract WindowLayoutInfo
getWindowLayoutInfo(@NonNull context: Context)

Get current window layout information for the provided Context.

abstract Unit
registerDeviceStateChangeCallback(@NonNull executor: Executor, @NonNull callback: Consumer<DeviceState!>)

Register a callback for device state changes.

abstract Unit
registerLayoutChangeCallback(@NonNull context: Context, @NonNull executor: Executor, @NonNull callback: Consumer<WindowLayoutInfo!>)

Register a callback for layout changes of the window of the current visual Context.

abstract Unit

Unregister a callback for device state changes.

abstract Unit

Unregister a callback for window layout changes of the Context window.

Public methods

getDeviceState

@NonNull abstract fun getDeviceState(): DeviceState

Get the current device state.

getWindowLayoutInfo

@NonNull abstract fun getWindowLayoutInfo(@NonNull context: Context): WindowLayoutInfo

Get current window layout information for the provided Context. Must be called only after the it is attached to the window and the layout pass has happened.

registerDeviceStateChangeCallback

abstract fun registerDeviceStateChangeCallback(
    @NonNull executor: Executor,
    @NonNull callback: Consumer<DeviceState!>
): Unit

Register a callback for device state changes.

registerLayoutChangeCallback

abstract fun registerLayoutChangeCallback(
    @NonNull context: Context,
    @NonNull executor: Executor,
    @NonNull callback: Consumer<WindowLayoutInfo!>
): Unit

Register a callback for layout changes of the window of the current visual Context. Must be called only after the it is attached to the window.

unregisterDeviceStateChangeCallback

abstract fun unregisterDeviceStateChangeCallback(@NonNull callback: Consumer<DeviceState!>): Unit

Unregister a callback for device state changes.

unregisterLayoutChangeCallback

abstract fun unregisterLayoutChangeCallback(@NonNull callback: Consumer<WindowLayoutInfo!>): Unit

Unregister a callback for window layout changes of the Context window.