android-coroutines-expert
Installation
SKILL.md
Coroutines & Concurrency Mastery โก๐งต
A strict rulebook to prevent thread-blocking, memory leaks, and lost UI events in modern Android applications.
โก When to Use
- ViewModel Logic: Launching coroutines for network/database requests.
- One-Time UI Events: Showing Snackbars, Toasts, or Navigation triggers.
- Parallel Work: Running multiple non-blocking tasks.
๐ฆ Rule 1: The UI Event Dilemma (StateFlow vs Channel)
You must explicitly distinguish between UI State (things that persist on rotation) and UI Events (things that happen once, like a Toast or Navigation).
- UI STATE: Use
MutableStateFlow. - UI EVENTS: Use an un-buffered
Channelexported as aFlow. NEVER useSharedFlowwithreplay = 0orMutableStateFlowfor one-time events, because if the app rotates, the event might be dropped or replayed twice.