SavedStateHandle vs. rememberSaveable: Which One Should You Choose?
A senior developer's guide to clean state management in Jetpack Compose—where to store your data and why it matters for app stability. TL;DR: SavedStateHandle: Use for Business/Presentation State (IDs, search queries) in the ViewModel. It is the most reliable anchor for process restoration. rememberSaveable: Use for Pure UI State (scroll position, animation toggles) in the Composable. Rule of Thumb: If losing the state breaks the screen’s logic, use the ViewModel. If it only resets a visual preference, keep it in the UI. 1. The Architecture Gap In a modern Jetpack Compose app, state lives in two distinct layers. Choosing the wrong bucket leads to “State Leakage,” where your business logic becomes tangled with your UI or your UI becomes unresponsive after a background kill. SavedStateHandle (The ViewModel Layer) This is your Architectural Anchor . It allows the ViewModel to interact with the system’s saved instance state. Because the ...