Originally published on Medium:
Unboxing ViewModel in Android
Ever wondered why your input fields reset on screen rotation? ViewModel is the solution.
In this short guide, you'll learn:
✅ What ViewModel actually does
✅ How to use it with LiveData in XML
✅ How to use it with StateFlow in Jetpack Compose
✅ A real-world example: input field validation
“Your UI may change — your logic shouldn’t. That’s the promise of ViewModel.”
Thanks for reading! 👋