android-coroutines

Enforce Kotlin Coroutines patterns for Android structured concurrency and lifecycle integration.

Updated May 29, 2016
One-click install
npx skills add https://github.com/AerisG222/maw-photos-android --skill android-coroutines-aerisg222
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: android-coroutines
Source: https://github.com/AerisG222/maw-photos-android/tree/main/.github/skills/android-coroutines
Command: npx skills add https://github.com/AerisG222/maw-photos-android --skill android-coroutines-aerisg222

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides a definitive guide to writing robust, efficient, and maintainable asynchronous code on Android using Kotlin Coroutines, ensuring applications remain responsive and free of common concurrency bugs.

Core Features & Use Cases

  • Structured Concurrency: Enforces proper scope management and cancellation for reliable background operations.
  • Lifecycle Integration: Safely handles asynchronous tasks tied to the Android component lifecycle.
  • Reactive Streams: Implements modern data flow patterns with Flow, StateFlow, and SharedFlow.
  • Use Case: Implement a ViewModel that fetches user data from a network API and displays it in the UI, ensuring that network requests are cancelled if the user navigates away before they complete.

Quick Start

Use the android-coroutines skill to implement a ViewModel that fetches data from a repository using coroutines and exposes it as a StateFlow.

Frequently Asked Questions about android-coroutines

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

FAQPage Schema
How do I implement structured concurrency in Android Kotlin coroutines?

Structured concurrency in Android Kotlin coroutines is enforced by managing coroutine scopes and ensuring proper cancellation for reliable background operations. This approach ties asynchronous tasks to specific lifecycles, preventing memory leaks and keeping applications responsive.

How do I expose asynchronous data streams from a ViewModel using Kotlin Flow?

You can expose asynchronous data streams from a ViewModel using Kotlin Flow by implementing modern reactive patterns with StateFlow and SharedFlow. This allows you to fetch data from a network API and display it in the UI while safely managing state.

How do I cancel network requests when a user navigates away in an Android app?

To cancel network requests when a user navigates away, integrate asynchronous tasks with the Android component lifecycle. By enforcing proper scope management, coroutines automatically cancel pending network requests when the associated ViewModel or lifecycle owner is destroyed.

What is the best way to test Android Kotlin coroutines and asynchronous logic?

The best way to test Android Kotlin coroutines is by using TestDispatcher. This approach handles asynchronous logic testing by controlling virtual time, ensuring deterministic and reliable test execution for your concurrent code.

Why does my Android coroutine scope outlive its ViewModel?

An Android coroutine scope outlives its ViewModel when lifecycle integration is improperly managed. To fix this, enforce structured concurrency by binding scope management and cancellability directly to the Android component lifecycle to ensure tasks are cancelled.