What problem does it solve?
This Skill provides guidance on implementing Android ViewModels effectively, focusing on modern state management patterns using StateFlow and SharedFlow for robust UI updates and event handling.
Core Features & Use Cases
- UI State Management: Learn to manage persistent UI states (loading, success, error) using
StateFlow.
- Event Handling: Understand how to handle transient UI events (toasts, navigation) with
SharedFlow.
- Lifecycle Awareness: Implement best practices for collecting flows within the Android Activity/Fragment lifecycle.
- Use Case: When building a data-fetching screen, use this Skill's patterns to display a loading indicator, show the fetched data upon success, and present an error message if the fetch fails, all while ensuring state is preserved across configuration changes.
Quick Start
Implement an Android ViewModel using StateFlow for UI state and SharedFlow for one-off events, collecting them in a Compose UI using collectAsStateWithLifecycle and LaunchedEffect.