android-kotlin-coroutines

Diagnose and improve Android Kotlin coroutine and Flow code for lifecycle safety.

1|Updated Feb 28, 2026
One-click install
npx skills add https://github.com/Binh230199/ai --skill android-kotlin-coroutines-binh230199
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: android-kotlin-coroutines
Source: https://github.com/Binh230199/ai/tree/main/.github/skills/android-kotlin-coroutines
Command: npx skills add https://github.com/Binh230199/ai --skill android-kotlin-coroutines-binh230199

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Helps Android developers write, review, debug, and migrate asynchronous Kotlin code without leaking scopes, mishandling cancellation, or collecting flows in unsafe lifecycles.

Core Features & Use Cases

  • Suspend functions and dispatcher usage for network, disk, and CPU-bound work.
  • Structured concurrency with scopes, jobs, exception handling, and cancellation-safe patterns.
  • Flow, StateFlow, SharedFlow, Channel, and callbackFlow patterns for state, events, and callback bridging.
  • Lifecycle-safe collection for Activities, Fragments, ViewModels, and Compose.
  • Deterministic coroutine testing with runTest, scheduler control, and flow assertions.
  • Use case: review an Android screen that freezes or leaks updates and trace whether the issue is a scope leak, bad dispatcher choice, or unsafe flow collection.

Quick Start

Ask for a coroutine or Flow review of your Android class and specify whether you want write, review, debug, or migrate guidance.

Frequently Asked Questions about android-kotlin-coroutines

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

FAQPage Schema
How do I prevent lifecycle leaks when collecting Kotlin Flow in Android Fragments?

To prevent lifecycle leaks when collecting Kotlin Flow in Android Fragments, use lifecycle-safe collection patterns like repeatOnLifecycle. This ensures flow collection suspends and cancels appropriately when the Fragment lifecycle drops below safe states.

Why does my Android coroutine scope leak updates when the screen freezes?

An Android coroutine scope leaks updates when the screen freezes due to bad dispatcher choices or unsafe flow collection. Diagnosing the scope leak helps trace whether the issue is structural concurrency failure or improper dispatcher injection.

How to test Kotlin coroutines deterministically with runTest and Turbine?

To test Kotlin coroutines deterministically with runTest and Turbine, control the virtual scheduler and use flow assertions. This approach eliminates flaky asynchronous behavior by validating suspend functions and shared state without real time delays.

What is the best way to bridge callbacks to Kotlin Flow in Android using callbackFlow?

The best way to bridge callbacks to Kotlin Flow in Android is using callbackFlow. It safely converts callback-based APIs into cold flows, allowing proper structured concurrency and cancellation-safe exception handling when the flow collector cancels.

Can I use structured concurrency with SharedFlow and Channel for one-time events in ViewModels?

Yes, you can use structured concurrency with SharedFlow and Channel for one-time events in ViewModels. StateFlow handles state, while SharedFlow and Channel expose events, ensuring dispatcher injection and cancellation-safe patterns.

When should I not use GlobalScope for Android Kotlin coroutines?

You should not use GlobalScope for Android Kotlin coroutines when the operation is tied to a specific screen or component. Using GlobalScope breaks structured concurrency, causing lifecycle leaks and preventing proper cancellation when the ViewModel or Activity is destroyed.