android-coroutines

Enforce structured concurrency and lifecycle safety for Kotlin Coroutines on Android.

1|2|Updated Jan 25, 2026
One-click install
npx skills add https://github.com/jhparktime/OnGuard --skill android-coroutines-jhparktime
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: android-coroutines
Source: https://github.com/jhparktime/OnGuard/tree/main/.claude/skills/android-coroutines
Command: npx skills add https://github.com/jhparktime/OnGuard --skill android-coroutines-jhparktime

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This guide compiles authoritative rules and patterns for writing production-quality Kotlin Coroutines on Android, emphasizing structured concurrency, lifecycle safety, and robust error handling.

Core Features & Use Cases

  • Structured concurrency and lifecycle integration for Android components (ViewModels, Activities, Fragments).
  • Safe, testable coroutine usage with main-safety, proper scope management, and Flow-based UI state.
  • Clear guidance for error handling, cancellation, and testing to prevent leaks and crashes.

Quick Start

Apply these rules to convert a ViewModel-based data fetch into a lifecycle-safe, testable coroutine flow.

Frequently Asked Questions about android-coroutines

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

FAQPage Schema
How do I ensure lifecycle safety when collecting Kotlin coroutines in Android?

Lifecycle safety in Kotlin coroutines is enforced by binding coroutine scopes to Android lifecycle components like ViewModels and using lifecycle-aware Flow collection to prevent memory leaks and crashes when views are destroyed.

What is structured concurrency in Android and why should I avoid GlobalScope?

Structured concurrency in Android means tying coroutines to specific lifecycle-bound scopes, ensuring automatic cancellation and error propagation. Avoiding GlobalScope prevents unmanaged background tasks that cause memory leaks and unpredictable app crashes.

How do I test Android coroutines for main-safety and dispatcher injection?

Test Android coroutines for main-safety by injecting dispatchers into your classes, allowing you to swap background and main thread dispatchers with test scopes during unit testing to verify synchronous execution and proper threading.

How do I manage mutable UI state with Kotlin Flow in an Android ViewModel?

Manage mutable UI state by encapsulating it inside an Android ViewModel and exposing a read-only Flow to the UI layer, ensuring safe asynchronous data loading and reactive state updates without exposing mutable state externally.

How do I handle errors and cancellation in Android Kotlin Coroutines?

Handle errors and cancellation in Android Kotlin Coroutines by implementing robust error handling mechanisms within specific coroutine scopes, ensuring that failed background processing or cancelled jobs propagate correctly without crashing the app.

Does this guide cover background processing and asynchronous data loading in Android?

Yes, this guide covers asynchronous data loading and background processing in Android apps by applying structured concurrency patterns, dispatcher injection, and proper ViewModel usage to achieve testable, production-grade code.