| name | android-viewmodel |
| description | Best practices for implementing Android ViewModels, specifically focused on StateFlow for UI state and SharedFlow for one-off events. |
Android ViewModel & State Management
Instructions
Use ViewModel to hold state and business logic. It must outlive configuration changes.
1. UI State (StateFlow)
2. One-Off Events (SharedFlow)
3. Collecting in UI
4. Scope
- Use
viewModelScope for all coroutines started by the ViewModel.
- Ideally, specific operations should be delegated to UseCases or Repositories.