Why ViewModel Survives Rotation
Keep state through configuration changes.
The Rotation Problem
Rotate the screen and Android destroys your Activity, wiping any state you stored in it. Your counter, text, and scroll position all vanish. 😵
Configuration Changes
Rotation is one of many configuration changes: theme switches, locale changes, and window resizing all recreate your screen the same way.
All lessons in this course
- Why ViewModel Survives Rotation
- viewModel() in a Composable
- Modeling a UiState Data Class
- collectAsStateWithLifecycle