Why does Android's ViewModel survive configuration changes but not process death, and how to design around it?
I've been working on an Android app using MVVM architecture with Jetpack components, and I understand that ViewModel
survives configuration changes (like screen rotations) but not process death (e.g., when the system kills the app to reclaim memory).
However, designing resilient apps that recover gracefully from process death is a challenge—especially when dealing with UI state, repository data, and navigation logic.
Here are some specific issues I’m facing:
-
How do you persist complex UI state across process death without bloating
SavedStateHandle
? -
What's the best practice to re-fetch or restore data when the ViewModel is re-instantiated after process death?
-
Should we rely solely on Room, DataStore, or use custom serialization strategies?
-
How do advanced apps like WhatsApp or Instagram manage such scenarios?
I’m looking for practical architecture patterns or design tips used in production-grade apps to make ViewModel and app state resilient beyond just configuration changes.
Any insights, sample code, or architecture diagrams would be greatly appreciated!
0 Answers
Need More Help?
Get personalized assistance with your technical questions.