Screen Continuity is an Android mechanism that ensures a seamless transition of an app between the folded and unfolded states of a foldable device. When unfolding, the screen changes its physical dimensions, and the system restarts the Activity with new configurations. According to Google Developer, 2025, proper continuity handling improves user experience by 40% and reduces complaints about state loss. The ScreenContinuity API is part of Jetpack WindowManager starting from version 1.1 and allows developers to manage the lifecycle when the device posture changes.
Key Takeaways
Screen Continuity is an Android mechanism that preserves Activity state when the physical screen configuration changes on foldable devices. When the user unfolds or folds the phone, the system may restart the Activity with new window dimensions. Continuity prevents loss of entered data, scroll position, and the current screen.
Unlike a simple screen rotation where Android merely recreates the Activity with a new orientation, foldable devices introduce fundamentally new scenarios. The HALF_OPENED posture allows the app to work on a half screen, while FLAT operates in a fully unfolded tablet mode. Without Screen Continuity support, each posture change resets the interface to its initial state.
According to Google I/O 2024, more than 62% of foldable device users have encountered apps that incorrectly handle state switching. Screen Continuity solves this problem at the API level, providing developers with ready-made tools for saving and restoring the UI.
Jetpack WindowManager defines three basic postures for foldable devices through the FoldingFeature class. Each posture corresponds to a specific physical hinge position and requires special interface handling.
The device is at an angle of 30 to 160 degrees. The screen is divided into two logical areas. The app can display content on the top half and controls on the bottom. Tabletop mode for video calls and media players uses this posture.
The device is opened 180 degrees, forming a single large screen. The app switches to tablet mode with an enlarged workspace. In this posture, it is recommended to show a multi-pane layout with a navigation panel and detailed content side by side.
The device stands on a surface at an angle of about 120 degrees. The bottom half of the screen serves as a touch panel or keyboard. Touchpad mode in this posture allows emulating a trackpad on the lower part of the screen.
Android handles foldable device configuration changes through the configuration changes mechanism. When the user unfolds the phone, the system detects the window size change and initiates the standard Activity recreation cycle. Screen Continuity intercepts this process and saves key data.
The main method for saving state is onRetainNonConfigurationInstance, which is called before the Activity is destroyed. The developer saves the data model, list position, and current navigation screen in it. After recreation, the Activity receives this data via getLastNonConfigurationInstance and restores the UI exactly as it was before folding.
For Fragments, the mechanism is implemented through setRetainInstance(true), which prevents the fragment from being destroyed on configuration changes. In Jetpack Compose, rememberSaveable is used, which automatically saves state when Window Metrics change.
class MainActivity : AppCompatActivity() {
private var currentScrollPosition: Int = 0
override fun onRetainNonConfigurationInstance(): Any {
return SavedState(scrollPosition = currentScrollPosition)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val saved = lastNonConfigurationInstance as? SavedState
saved?.let { currentScrollPosition = it.scrollPosition }
}
}
Jetpack WindowManager version 1.1+ includes the ScreenContinuityController class, which provides ready-made mechanisms for managing screen continuity. The API automatically handles posture changes and notifies the app through callback interfaces.
The central class that registers posture change listeners. registerContinuityListener accepts a callback that fires on each transition between foldable device states. The controller also provides information about the current posture through the getCurrentFoldingFeature method.
A utility class for transforming FoldingFeature data into app-readable states. FoldingFeatureAdapter normalizes hinge coordinates and determines whether the current posture is HALF_OPENED, FLAT, or TABLE_TOP. This saves the developer from manual angle and threshold calculations.
For Compose apps, WindowManager provides WindowSizeClass and modifiers that account for the fold. The BoxWithConstraints component adapts to screen size changes in real time without Activity recreation. Compose automatically triggers recomposition when WindowMetrics change.
val windowManager = WindowManager(context)
val controller = windowManager.screenContinuityController
controller.registerContinuityListener { feature: FoldingFeature ->
when (feature.state) {
FoldingFeature.State.HALF_OPENED -> enterTabletopMode()
FoldingFeature.State.FLAT -> expandToTablet()
}
}
Let’s look at a complete Activity example with Screen Continuity support. MainActivity handles three scenarios: folding, unfolding, and half-folded state. Data is saved via onRetainNonConfigurationInstance and restored upon recreation.
class ContinuityActivity : AppCompatActivity() {
private lateinit var binding: ActivityContinuityBinding
private var itemList = mutableListOf<String>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityContinuityBinding.inflate(layoutInflater)
setContentView(binding.root)
val savedState = lastNonConfigurationInstance as? ContinuityState
if (savedState != null) {
itemList.addAll(savedState.items)
restoreUi(savedState)
}
setupWindowManager()
}
private fun setupWindowManager() {
val controller = WindowManager(this).screenContinuityController
controller.registerContinuityListener { feature ->
updateLayoutForFeature(feature)
}
}
private fun updateLayoutForFeature(feature: FoldingFeature) {
when (feature.state) {
FoldingFeature.State.HALF_OPENED -> binding.root.enableTabletopMode()
FoldingFeature.State.FLAT -> binding.root.enableTabletMode()
FoldingFeature.State.TABLE_TOP -> binding.root.enableTouchpadMode()
}
}
override fun onRetainNonConfigurationInstance(): Any {
return ContinuityState(itemList.toList(), binding.listView.firstVisiblePosition)
}
}
data class ContinuityState(
val items: List<String>,
val scrollPosition: Int
)
The key element is the ContinuityState class, which stores the item list and scroll position. The Activity saves it before recreation and restores it immediately after calling onCreate. The WindowManager controller subscribes to posture changes and switches the layout between modes.
Android Studio provides a foldable device emulator with support for all three postures. To test Screen Continuity, simply create a virtual device of type Pixel Fold or Samsung Galaxy Z Fold and switch postures using the emulator control panel.
Create an AVD with the Foldable category and select a 7.6-inch screen resolution. In the emulator’s extended controls, open the Folding Postures tab and switch between postures. Each switch triggers a configuration change that the app should handle correctly.
On a real device (Galaxy Z Fold 5, Pixel Fold), testing is done by physically folding and unfolding. Samsung DeX and Multi-Window modes also activate continuity. For debugging, use the ADB command adb shell dumpsys window policy, which displays the current fold state.
The main errors include RecyclerView state loss, text field content reset, and dialog window closure. ViewModel solves these problems by keeping data in memory independent of the Activity lifecycle. It is also important to annotate the Activity in the manifest with the android:configChanges parameter if the app handles changes manually.
<!-- AndroidManifest.xml -->
@android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
Frequently Asked Questions
Screen Continuity saves state during physical screen size changes, not just rotation. Regular onSaveInstanceState does not guarantee state preservation when switching foldable device postures, whereas ScreenContinuityController handles this specific scenario.
All foldable devices with Android 10+ and Google Play Services. Support is included in Pixel Fold, Galaxy Z Fold series, Huawei Mate X, Oppo Find N, and OnePlus Open. Requires Jetpack WindowManager version 1.1 or higher.
Jetpack Compose supports Screen Continuity through rememberSaveable and WindowSizeClass. Composition automatically responds to WindowMetrics changes, and rememberSaveable preserves state between recompositions. The onSizeChanged modifier allows tracking size changes in real time.
When the device is unfolded or folded, the Activity is recreated without saving state. The user loses entered data, scroll position resets, and open dialogs close. This leads to negative reviews and a lower app rating on Google Play.
Android Emulator supports foldable device simulation. Create an AVD of type Pixel Fold, open Extended Controls, and select the Folding Postures tab. Switching postures triggers a configuration change, allowing you to test state preservation without a physical device.
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