shekhar23/claude-zero-to-hero-android-kmp/android-coroutines-flow
Claude Code and agent skill by shekhar23/claude-zero-to-hero-android-kmp
- community
Checking that the SKILL.md file is still in the repository.
Coroutines and Flow patterns for Android/KMP - dispatcher ownership, StateFlow vs SharedFlow, combine/mapLatest/debounce, cancellation, sharing, and collection in ViewModels and Compose. Use this skill whenever writing async code, exposing streams from repositories, transforming Flow, coordinating parallel work, or reviewing coroutine scope usage. Trigger on phrases like "Flow", "StateFlow", "SharedFlow", "coroutines", "dispatcher", "launch", "async", "combine", "mapLatest", "debounce", "retryWhen", or "collectLatest".
Install
npx vskill@latest install shekhar23/claude-zero-to-hero-android-kmp/android-coroutines-flowSKILL.md
Android / KMP Coroutines and Flow
Core Principles
- Prefer
suspendfor one-shot work andFlowfor streams over time. ViewModelowns UI-facing coroutine scopes.- Repositories expose
Flowonly when data can change over time; otherwise returnsuspendfunctions. - Cancellation is expected behavior, not an error.
- Never block the main thread with disk, network, or heavy CPU work.
Choosing the Right API
| Need | Preferred API | |
|---|---|---|
| Single request/response | suspend fun | |
| Ongoing database observation | Flow<T> | |
| UI state stream | StateFlow<T> | |
| One-time events | Channel + receiveAsFlow() | |
| Fire-and-forget parallel child work | coroutineScope { async { ... } } |
Do not use LiveData in new code.
Dispatcher Ownership
The class doing the blocking work is responsible for moving to the correct dispatcher.
ViewModels that only use viewModelScope should not inject dispatchers. See the android-testing skill for test setup with Dispatchers.setMain(...).
Repository Contracts
Use Flow only when the caller should keep receiving updates:
Bad patterns:
- returning
Flowfor a one-time network request - launching internal background jobs that the caller cannot control
- collecting a
Flowinside the repository just to emit into anotherFlow
StateFlow in ViewModels
Expose immutable state only:
Use .update { } for all mutations:
For UI state derived from multiple sources, prefer combine:
SharedFlow vs Channel
- Use
StateFlowfor persistent UI state. - Use
Channel+receiveAsFlow()for one-time events such as navigation or snackbars. - Use
MutableSharedFlowonly when multiple collectors need the same transient stream and replay behavior is intentional.
Avoid using StateFlow for navigation events; it can replay stale events after configuration changes.
Flow Operators That Usually Matter
mapLatest
Cancel previous work when newer input arrives:
combine
Join multiple reactive sources into one UI model:
flatMapLatest
Switch to a new stream when the upstream key changes:
catch
Only recover from upstream exceptions you truly own. Do not swallow CancellationException.
Collecting in the ViewModel
Collect long-lived streams in viewModelScope:
Prefer launchIn(viewModelScope) for passive observation pipelines and viewModelScope.launch { flow.collect { ... } } when you need imperative branching.
Compose Collection
Always collect state in composables with lifecycle awareness:
Do not collect arbitrary flows in deeply nested composables. Keep collection in Root composables and pass plain state down. See the android-presentation-mvi skill.
Parallel Work
Use structured concurrency so child work is cancelled with the parent:
Use supervisorScope only when one child failure should not cancel sibling work.
Retry and Backoff
Prefer explicit retries at boundaries like sync or network refresh:
Do not add hidden infinite retries to generic repository functions.
Checklist: Adding Coroutine / Flow Logic
- [ ] Use
suspendfor one-shot work andFlowfor ongoing streams - [ ] Move blocking work to the owning dispatcher with
withContext(...) - [ ] Expose immutable
StateFlowfrom theViewModel - [ ] Use
Channelfor one-time events - [ ] Collect UI state with
collectAsStateWithLifecycle() - [ ] Never swallow
CancellationException
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/android-coroutines-flow/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/shekhar23/claude-zero-to-hero-android-kmp/android-coroutines-flow)