← Android App Development (Kotlin) learning path
Android App Development (Kotlin) · Module 6 of 10

Architecture: ViewModel and MVVM

Structure apps with ViewModel, repositories and clean layers.

📖 Key ideas

  1. MVVM: Model (data), View (UI), ViewModel (state + logic).
  2. ViewModel survives rotation and holds UI state.
  3. Expose state with StateFlow; UI collects it.
  4. Repository pattern hides data sources (network, database).
  5. 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