mediumConceptScenarioMidSenior
How does a ViewModel survive a configuration change, and what does it not survive that SavedStateHandle is for?
4 min readUpdated 2026-08-15
Answer
Short answer
A ViewModel outlives a configuration change like rotation because the Activity is recreated while the ViewModelStore is retained, but it does not survive process death from memory pressure, which is what SavedStateHandle exists to restore state across.
Keep android explicit in the answer because that is the concept the interviewer is actually trying to test. A good android explanation names the trade-off, the failure mode, and the evidence you would use before choosing.
Was this answer helpful?
Likely follow-ups
- How would you test that your screen restores correctly after system-initiated process death, given that a debugger attached usually prevents it?
- What kind of data belongs in SavedStateHandle versus what belongs in a database or a repository cache?
- Why can't you put a large object like a Bitmap directly into SavedStateHandle?
- What is the practical difference between onCleared() being called and the process being killed without any callback at all?
Related questions
- A deep link opens the right screen when the app is in the background and the wrong one when the app was killed. How do you test for that?mediumAlso on android5 min
- How do you choose which devices to test on, and what will an emulator never tell you?mediumAlso on android5 min
- A Compose screen with a long list is janky while scrolling - walk through how you'd find and fix the recomposition problem causing it.mediumAlso on android5 min
- What does structured concurrency actually give you in Kotlin coroutines, and how does a coroutine scope leak happen despite it?mediumAlso on android4 min