0PricingLogin
Jetpack Compose Academy · Lesson

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

  1. Why ViewModel Survives Rotation
  2. viewModel() in a Composable
  3. Modeling a UiState Data Class
  4. collectAsStateWithLifecycle
← Back to Jetpack Compose Academy