Using rememberSaveable helps your app keep UI state during configuration changes like screen rotation without reloading data. This reduces unnecessary recompositions and data fetching, helping maintain smooth 60fps animations and interactions. It uses minimal memory by saving only small state objects, so battery impact is low.
rememberSaveable for configuration changes in Android Kotlin - Build, Publish & Deploy
To keep your app running smoothly at 60fps, use rememberSaveable only for small, simple state data like strings or numbers. Avoid saving large objects or complex data structures directly. Use custom Saver implementations if needed to optimize serialization. This reduces overhead during state restoration and keeps UI updates fast.
rememberSaveable is part of Jetpack Compose and adds negligible size to your app bundle. It does not affect startup time significantly because state restoration happens asynchronously during recomposition. Keeping saved state small helps avoid delays in UI rendering after configuration changes.
Android: rememberSaveable is designed for Android Compose apps to survive configuration changes like rotation or multi-window mode. It uses SavedStateRegistry under the hood.
iOS: iOS apps use different state preservation methods, typically relying on SwiftUI's @State and @SceneStorage for similar behavior. There is no direct rememberSaveable equivalent.
- Ensure your app handles configuration changes gracefully without crashes or data loss, as poor UX can lead to rejection.
- Do not save sensitive user data in
rememberSaveablestate since it can be serialized and restored; use secure storage instead. - Follow Android's privacy and data handling policies when saving state.
Your app takes 5 seconds to load this screen after rotation. What's likely wrong?
- You might be saving large or complex objects with
rememberSaveable, causing slow serialization. - Or you are fetching data again instead of restoring saved state.
- Check if you can simplify saved state or preload data efficiently.