← Android App Development (Kotlin) learning pathAndroid App Development (Kotlin) · Module 6 of 10
Architecture: ViewModel and MVVM
Structure apps with ViewModel, repositories and clean layers.
📖 Key ideas
- MVVM: Model (data), View (UI), ViewModel (state + logic).
- ViewModel survives rotation and holds UI state.
- Expose state with StateFlow; UI collects it.
- Repository pattern hides data sources (network, database).
- Dependency injection with Hilt.
💡 Real-life example: The ViewModel is a manager between customers (UI) and the godown (repository).
ViewModelHolds UI state across config changes
StateFlowObservable state stream
RepositorySingle source for data access
HiltDependency injection library