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 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 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.
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.
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.
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 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.
| WindowSizeClass | Screen Width | Example Device | Recommended Layout |
|---|---|---|---|
| Compact | 0–599dp | Pixel 8, Galaxy S24 | Single-pane, bottom navigation |
| Medium | 600–839dp | Pixel Fold (folded), iPad Mini | List-detail, side navigation |
| Expanded | 840dp+ | Galaxy Z Fold (unfolded), iPad Pro | Multi-pane, navigation rail |
class MyComposable {
@Composable
fun AdaptiveLayout(windowSizeClass: WindowSizeClass) {
when (windowSizeClass.widthSizeClass) {
WindowWidthSizeClass.Compact -> CompactScreen()
WindowWidthSizeClass.Expanded -> ExpandedScreen()
else -> MediumScreen()
}
}
}
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.
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.
val controller = WindowManager(context).screenContinuityController
controller.registerContinuityListener { feature ->
if (feature.state == FoldingFeature.State.FLAT) {
logContinuityEvent("Device unfolded")
}
}
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.
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.
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.
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.
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
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.
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.
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.
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.
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
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.
Read also