DEV Community

Vrushali
Vrushali

Posted on • Originally published at Medium

Unboxing ViewModel in Android: LiveData vs StateFlow

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! 👋

Top comments (0)