How does a ViewModel survive configuration changes and what is its scope?

WHAT IT TESTS: knowledge of ViewModelStore and lifecycle scope. ANSWER OUTLINE: the framework retains ViewModels in a store scoped to an Activity or Fragment across config changes, clearing them only when the owner finishes for good.
WHAT IT TESTS: your understanding of ViewModelStore ownership and how the framework distinguishes temporary destruction from permanent finish. ANSWER OUTLINE: the system keeps ViewModels in a ViewModelStore scoped to an Activity or Fragment; the store survives config changes because the framework reuses it across recreation, but it clears when the owner receives onDestroy without an upcoming recreation, such as when the user exits. RED FLAG: confusing ViewModel retention with onSaveInstanceState or suggesting static references are involved.
Read the original → developer.android.com
- #android
- #viewmodel
- #lifecycle
- #configuration-changes
- #jetpack
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.