midAndroid
What is ViewModel in Android?
Updated Feb 20, 2026
Short answer
ViewModel stores UI-related data and survives configuration changes like screen rotation.
Deep explanation
🔹 Key Features
- Lifecycle-aware
- Survives rotation
- Holds UI state
---
🖼️
Markdown
---
🔹 Why Important
- Prevents data loss
- Clean separation of UI & logic
Real-world example
Login screen retains user input after rotation.
Common mistakes
- Storing context in ViewModel
Follow-up questions
- ViewModel vs LiveData?