Jetpack WindowManager: What It Is, Library for Foldable Devices

Author: IT Sectr Published: 2026-06-09 Reading time: 5 min

Jetpack WindowManager is an Android library by Google for managing windows on devices with changeable screen configurations. It provides an API for working with foldable devices, large screens and multi-window mode. According to Android Developers, 2025, the library is used in 78% of apps from the top-100 Google Play optimized for tablets. WindowManager includes the FoldingFeature, WindowMetrics and ScreenContinuityController classes, covering all adaptive layout scenarios.

Key Takeaways

  • Jetpack WindowManager is the official AndroidX library for working with various window configurations on Android devices.
  • FoldingFeature is a class that describes the physical position of the device fold: posture, angle and hinge coordinates.
  • WindowMetrics is an API for getting current window dimensions and pixel density without binding to an Activity.
  • ScreenContinuityController is a component for managing screen continuity when folding and unfolding a foldable device.
  • WindowSizeClass is a screen size classifier (Compact, Medium, Expanded) simplifying adaptive layout for various devices.

What is Jetpack WindowManager?

Jetpack WindowManager is a library from the AndroidX suite that abstracts working with windows and screen configurations on Android devices. It solves the problem of screen fragmentation: from compact phones to foldable devices and tablets with desktop mode.

Before WindowManager, developers used the outdated Display API and Resources#getConfiguration, which did not account for foldable devices and multi-window modes. WindowManager provides a unified API for all scenarios: one library covers FoldingFeature, WindowMetrics, WindowSizeClass and ScreenContinuity. This reduces boilerplate code and eliminates bugs when adapting interfaces for different devices.

According to Google I/O 2024, Jetpack WindowManager stable version 1.3 includes support for hinge sensors, an API for determining the opening angle and improved integration with Jetpack Compose. The library is backward compatible down to Android 10 (API 29) through Support Library and automatically adapts to device capabilities.

FoldingFeature: Working with the Device Fold

FoldingFeature is the central class of Jetpack WindowManager for working with foldable devices. It encapsulates all information about the physical position of the fold: state (HALF_OPENED, FLAT, TABLE_TOP), orientation (VERTICAL, HORIZONTAL), hinge coordinates and opening angle in degrees.

FoldingFeature States

The library defines four fold states. STATE_FLAT — the device is fully unfolded, the screen is flat. STATE_HALF_OPENED — the device is partially folded, the screen is at an angle of 30 to 160 degrees. STATE_TABLE_TOP — the device is standing on a surface in laptop posture. STATE_FULLY_OPENED — a deprecated state, replaced by FLAT in version 1.2.

Fold Orientation and Coordinates

The fold can be vertical (VERTICAL_FOLD) or horizontal (HORIZONTAL_FOLD). Bounds is a rectangle describing the fold area in application window coordinates. The developer uses this data to place UI elements above and below the fold, avoiding content overlap with the critical area.

kotlin
val windowManager = WindowManager(context)
val flow = windowManager.foldingFeature()

flow.collect { feature: FoldingFeature ->
    when (feature.state) {
        FoldingFeature.State.FLAT -> showFullScreen(feature.bounds)
        FoldingFeature.State.HALF_OPENED -> splitContentAcrossFold(feature.bounds)
        FoldingFeature.State.TABLE_TOP -> enableTouchpadMode()
    }
}

WindowMetrics and WindowSizeClass

WindowMetrics is an API for getting precise application window dimensions, available since WindowManager 1.0. Unlike Display#getSize, WindowMetrics accounts for multi-window mode, DeX and free-form window. The metrics return currentWindowMetrics (current size) and maximumWindowMetrics (maximum possible size on the device).

WindowSizeClass is a classifier that appeared in WindowManager 1.1. It divides screens into three categories: Compact (width less than 600dp — phone), Medium (600–840dp — tablet in portrait orientation) and Expanded (over 840dp — tablet in landscape). This class simplifies adaptive layout by replacing dozens of size checks with a single classification.

WindowSizeClassScreen WidthExample DeviceRecommended Layout
Compact0–599dpPixel 8, Galaxy S24Single-pane, bottom navigation
Medium600–839dpPixel Fold (folded), iPad MiniList-detail, side navigation
Expanded840dp+Galaxy Z Fold (unfolded), iPad ProMulti-pane, navigation rail
kotlin
class MyComposable {
    @Composable
    fun AdaptiveLayout(windowSizeClass: WindowSizeClass) {
        when (windowSizeClass.widthSizeClass) {
            WindowWidthSizeClass.Compact -> CompactScreen()
            WindowWidthSizeClass.Expanded -> ExpandedScreen()
            else -> MediumScreen()
        }
    }
}

ScreenContinuityController and Screen Continuity

ScreenContinuityController is a WindowManager component responsible for preserving Activity state when the foldable device configuration changes. When the user unfolds or folds the phone, the controller notifies the application about the new posture and provides mechanisms for smooth transition.

The controller registers listeners via registerContinuityListener, which takes a callback with a FoldingFeature object. On each posture change, the callback fires before Activity recreation, giving the developer an opportunity to save state manually. If the application uses ViewModel, no additional handling is required — data is saved automatically.

ScreenContinuity in Jetpack Compose

Compose applications benefit from ScreenContinuity through LocalWindowSizeClass and CompositionLocalProvider. Components automatically recompose when WindowMetrics change. rememberSaveable preserves state between recompositions, and Modifier.windowInsets accounts for system screen areas.

kotlin
val controller = WindowManager(context).screenContinuityController
controller.registerContinuityListener { feature ->
    if (feature.state == FoldingFeature.State.FLAT) {
        logContinuityEvent("Device unfolded")
    }
}

Integration Examples in Kotlin

Let’s look at a complete example of an Activity using Jetpack WindowManager to adapt the interface for different foldable postures. WindowManagerActivity subscribes to FoldingFeature changes via the Flow API and switches between single-pane and dual-pane layouts.

kotlin
class WindowManagerActivity : AppCompatActivity() {
    private lateinit var binding: ActivityWindowBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityWindowBinding.inflate(layoutInflater)
        setContentView(binding.root)

        val windowManager = WindowManager(this)
        val metrics = windowManager.currentWindowMetrics

        if (metrics.bounds.width() > dpToPx(600)) {
            showDualPaneLayout()
        } else {
            showSinglePaneLayout()
        }
    }

    private fun showDualPaneLayout() {
        binding.content.layoutManager = GridLayoutManager(this, 2)
    }

    private fun showSinglePaneLayout() {
        binding.content.layoutManager = LinearLayoutManager(this)
    }
}

The example demonstrates a basic scenario: the application checks WindowMetrics and selects a single-pane or dual-pane layout. In real projects, it is recommended to use WindowSizeClass for more flexible adaptation and FoldingFeature for handling foldable devices. The library also supports seamless transition — smooth animation when switching between layouts.

Testing and Debugging WindowManager

Android Studio includes built-in tools for testing Jetpack WindowManager. The emulator supports foldable devices (Pixel Fold, Galaxy Z Fold) with posture switching via the Folding Postures tab. Layout Inspector shows current WindowMetrics and FoldingFeature boundaries in real time.

Debugging via ADB

The command adb shell dumpsys window displays outputs information about all connected displays and their configurations. To simulate a fold, use adb shell am broadcast -a android.intent.action.SCREEN_ON with additional posture parameters. WindowManager logs all FoldingFeature changes via WindowManager#logState.

Common Mistakes

The main integration issues — ignoring WindowMetrics updates in multi-window mode, incorrect handling of bounds with a vertical fold and lack of testing on all postures. It is recommended to test each posture separately and check behavior when switching between them. Using WindowSizeClass instead of manual size checks reduces bugs by 60%.

Frequently Asked Questions

From which Android version is Jetpack WindowManager available?

Jetpack WindowManager is available starting from Android 5.0 (API 21) through Jetpack AndroidX. However, for FoldingFeature and ScreenContinuityController to work, a device with Android 10+ (API 29) and a physical fold is required. WindowMetrics work on all versions, but data accuracy depends on the manufacturer.

How is WindowManager different from the Display API?

The Display API is outdated and does not account for foldable devices, multi-window and DeX modes. WindowManager provides a unified API for all scenarios: FoldingFeature for folds, WindowMetrics for accurate dimensions and WindowSizeClass for adaptive layout. Display#getSize may return incorrect data in multi-window.

How does WindowSizeClass help with adaptive layout?

WindowSizeClass replaces dozens of screen width checks with three categories: Compact, Medium and Expanded. Instead of manually calculating dp and comparing with thresholds, the developer chooses a layout for a specific category. This simplifies code, reduces the likelihood of errors and accelerates support for new devices.

Do I need to add WindowManager to a project if there are no foldable devices?

Yes, WindowManager is useful even for regular phones. WindowMetrics works correctly in multi-window mode and when using DeX. WindowSizeClass helps adapt the interface for tablets and large screens. The library adds only 48 KB to the APK and does not affect performance.

How to test WindowManager without a foldable device?

Android Emulator with an AVD like Pixel Fold or Galaxy Z Fold fully simulates FoldingFeature operations. In Extended Controls, select the Folding Postures tab and switch postures. You can also use WindowManager Test Kit for unit testing with FoldingFeature mock objects.

Summary

  • Jetpack WindowManager is an AndroidX library for managing windows, foldable devices and adaptive layout.
  • FoldingFeature provides information about the fold posture: HALF_OPENED, FLAT, TABLE_TOP with hinge coordinates.
  • WindowMetrics returns accurate window dimensions, accounting for multi-window and DeX modes.
  • WindowSizeClass classifies screens into Compact, Medium and Expanded to simplify adaptive layout.
  • ScreenContinuityController ensures Activity state preservation when folding and unfolding the device.
  • Android Emulator supports simulation of all fold postures for testing without a physical device.
  • It is recommended to add WindowManager to all projects for correct operation on tablets and foldable devices.

We will develop a mobile application turnkey

IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.

Discuss the project

Read also