android-coroutines

Enforce structured concurrency and lifecycle-aware coroutine patterns in Android apps.

349|154|Updated Feb 18, 2021
One-click install
npx skills add https://github.com/livekit/client-sdk-android --skill android-coroutines-livekit
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: android-coroutines
Source: https://github.com/livekit/client-sdk-android/tree/main/.agent/skills/android-coroutines
Command: npx skills add https://github.com/livekit/client-sdk-android --skill android-coroutines-livekit

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Codifying authoritative rules and patterns to write production-quality Kotlin Coroutines code on Android, reducing boilerplate, errors, and lifecycle-related mistakes.

Core Features & Use Cases

  • Enforces structured concurrency, lifecycle safety, and reactive streams (Flow, StateFlow, SharedFlow, callbackFlow).
  • Provides patterns for scope management (viewModelScope, lifecycleScope) and safe collection with repeatOnLifecycle.
  • Guides on error handling, cancellation, and testing with TestDispatcher and runTest.

Quick Start

Apply these coroutine guidelines to refactor an Android component to use structured concurrency and lifecycle-aware flows.

Frequently Asked Questions about android-coroutines

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write lifecycle-aware Kotlin coroutines on Android?

To write lifecycle-aware Kotlin coroutines on Android, use viewModelScope or lifecycleScope for structured concurrency and collect flows safely with repeatOnLifecycle to prevent memory leaks.

What is structured concurrency in Android coroutines and why does it matter?

Structured concurrency in Android coroutines ensures every launched job is tied to a specific scope, preventing unmanaged background tasks and automatically canceling operations when their parent scope is destroyed.

How do I handle errors and cancellation in Kotlin Flow on Android?

Handle errors and cancellation in Kotlin Flow by applying structured concurrency patterns that enforce proper scope management, ensuring active coroutines are safely canceled when an exception occurs or the lifecycle ends.

What is the best way to test Android coroutines and Flow?

The best way to test Android coroutines and Flow is using runTest with a TestDispatcher to control virtual time, validate cancellation behavior, and verify asynchronous data-fetching logic without flakiness.

When should I use callbackFlow instead of standard Flow on Android?

Use callbackFlow instead of standard Flow on Android when converting callback-based asynchronous APIs into cold streams, allowing structured concurrency to manage active listener registration and safe cancellation.

Do I need dependency-injected dispatchers for Android coroutines?

Yes, dependency-injected dispatchers are required for Android coroutines to enforce structured concurrency, enabling seamless swapping of IO and Main dispatchers during testing with TestDispatcher.