MediumConceptAndroid in depth
What is the ViewModel and why does it survive configuration changes?
What a good answer covers
A ViewModel holds UI state and is retained across configuration changes such as rotation because it is scoped to a lifecycle owner that outlives the recreated Activity, and it is cleared when the owner is finished.
PreviousWhat is the Android Activity lifecycle?Next What do Kotlin coroutines and Flow offer on Android?