tezvyn:

How does a ViewModel survive configuration changes?

Source: developer.android.comintermediate

Tests understanding of lifecycle-aware components. ViewModels are retained by a ViewModelStore owned by the Activity/Fragment, which survives configuration changes. The ViewModel is cleared only when its scope is permanently finished.

Tests your understanding of how ViewModel solves state preservation during configuration changes, distinct from process death. A great answer explains that ViewModels are tied to a ViewModelStore, which is not destroyed on rotation. The new Activity instance gets the same ViewModel. The ViewModel's `onCleared()` is called only when the Activity is permanently finished. A red flag is confusing ViewModel's role with `onSaveInstanceState`, which handles process death.

Read the original → developer.android.com

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

How does a ViewModel survive configuration changes? · Tezvyn