Jetpack Compose rememberSaveable: Preserve UI State Across Configuration Changes
rememberSaveable automatically saves and restores Jetpack Compose UI state across configuration changes using a Bundle-like mechanism. Covers usage, bundle limits, and common pitfalls with practical examples.
02 Jun 2026, 15:13 UTC

Preserve UI state across configuration changes with rememberSaveable
When Android recreates an activity on rotation or other configuration changes, Jetpack Compose recomposes the UI. Without explicit persistence, transient input or selection data resets. rememberSaveable solves this by automatically saving state to a Bundle and restoring it on recomposition.
How rememberSaveable works
rememberSaveable extends remember by serializing the state into a Bundle during composition shutdown and deserializing it when the composable is recreated. The mechanism is transparent: declare state with rememberSaveable and Compose handles save/restore.
Worked example
@Composable
fun NameField() {
// State survives rotation and other config changes
val name by rememberSaveable { mutableStateOf("") }
OutlinedTextField(
value = name,
onValueChange = { name = it },
label = { Text("Enter name") }
)
}
After a device rotation, the text field retains the previously entered text instead of resetting to empty.
Limits and common mistakes
- The saved Bundle has a practical ceiling of ~500 KB on older devices. Storing large collections, bitmaps, or long strings may trigger
TransactionTooLargeException. For heavy data, persist externally and save only a reference key. - Passing a custom data class without
ParcelableorSerializablecauses a runtimeClassNotFoundException. ImplementParcelableor provide a customSaver. - Do not use
rememberandrememberSaveablefor the same mutable state; they use different storage scopes and will conflict.
Verification steps
- Add a
OutlinedTextFieldusingrememberSaveable, enter text, rotate the device, and confirm the value persists. - Use Android Studio's Memory Profiler or Logcat to inspect the saved Bundle and confirm keys and values are correctly stored and restored.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.