# Android Coroutines

Authoritative rules and patterns for production-quality Kotlin Coroutines onto Android.

- Repository: https://github.com/new-silvermoon/awesome-android-agent-skills (998 stars)
- Category: Mobile
- License: Apache-2.0
- Last updated: 2026-07-27
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add new-silvermoon/awesome-android-agent-skills --skill android-coroutines -g -a claude-code -y`
Codex: `npx skills add new-silvermoon/awesome-android-agent-skills --skill android-coroutines -g -a codex -y`
Cursor: `npx skills add new-silvermoon/awesome-android-agent-skills --skill android-coroutines -g -a cursor -y`
Gemini CLI: `npx skills add new-silvermoon/awesome-android-agent-skills --skill android-coroutines -g -a gemini-cli -y`

## Description

Authoritative rules and patterns for production-quality Kotlin Coroutines onto Android. Covers structured concurrency, lifecycle integration, and reactive streams.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Android Coroutines Expert Skill

This skill provides authoritative rules and patterns for writing production-quality Kotlin Coroutines code on Android. It enforces structured concurrency, lifecycle safety, and modern best practices (2025 standards).

## Responsibilities

*   **Asynchronous Logic**: Implementing suspend functions, Dispatcher management, and parallel execution.
*   **Reactive Streams**: Implementing `Flow`, `StateFlow`, `SharedFlow`, and `callbackFlow`.
*   **Lifecycle Integration**: Managing scopes (`viewModelScope`, `lifecycleScope`) and safe collection (`repeatOnLifecycle`).
*   **Error Handling**: Implementing `CoroutineExceptionHandler`, `SupervisorJob`, and proper `try-catch` hierarchies.
*   **Cancellability**: Ensuring long-running operations are cooperative using `ensureActive()`.
*   **Testing**: Setting up `TestDispatcher` and `runTest`.

## Applicability

Activate this skill when the user asks to:
*   "Fetch data from an API/Database."
*   "Perform background processing."
*   "Fix a memory leak" related to threads/tasks.
*   "Convert a listener/callback to Coroutines."
*   "Implement a ViewModel."
*   "Handle UI state updates."

## Critical Rules & Constraints

### 1. Dispatcher Injection (Testability)
*   **NEVER** hardcode Dispatchers (e.g., `Dispatchers.IO`, `Dispatchers.Default`) inside classes.
*   **ALWAYS** inject a `CoroutineDispatcher` via the constructor.
*   **DEFAULT** to `Dispatchers.IO` in the constructor argument for convenience, but allow it to be overridden.

```kotlin
// CORRECT
class UserRepository(
    private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
) { ... }

// INCORRECT
class UserRepository {
    fun getData() = withContext(Dispatchers.IO) { ... }
}
```

The rest: https://github.com/new-silvermoon/awesome-android-agent-skills/blob/HEAD/.github/skills/concurrency_and_networking/android-coroutines/SKILL.md
