android-coroutines

Standardize Kotlin Coroutines in Android apps with ViewModels, lifecycle-aware components, and Flow.

1|Updated Sep 7, 2025
One-click install
npx skills add https://github.com/sahuadarsh0/Wallet --skill android-coroutines-sahuadarsh0
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: android-coroutines
Source: https://github.com/sahuadarsh0/Wallet/tree/main/.cursor/skills/android-coroutines
Command: npx skills add https://github.com/sahuadarsh0/Wallet --skill android-coroutines-sahuadarsh0

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Android apps often suffer from uncontrolled asynchronous code, leading to leaks, crashes, and hard-to-maintain threading. This skill enforces structured concurrency, lifecycle safety, and modern coroutine best practices to deliver robust, testable, and scalable code.

Core Features & Use Cases

  • Structured concurrency guarantees across components (ViewModel, Repository, and Data layer)
  • Lifecycle-aware coroutine management using viewModelScope, lifecycleScope, and repeatOnLifecycle
  • Flow-based state management with StateFlow/SharedFlow and proper error handling
  • Testing support with TestDispatcher and runTest for deterministic tests

Quick Start

Implement a production-grade coroutine pattern by wiring a ViewModel with viewModelScope, expose UI state via StateFlow, and inject a testable dispatcher.

Frequently Asked Questions about android-coroutines

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

FAQPage Schema
How do I prevent memory leaks when using Kotlin coroutines in Android ViewModels?

Prevent coroutine memory leaks by enforcing structured concurrency with lifecycle-aware scopes like viewModelScope. This ensures background jobs are automatically cancelled when the ViewModel is destroyed, maintaining main-safety and preventing crashes.

What is the best way to manage UI state streams in Android using Kotlin Flow?

Manage UI state streams by exposing data through StateFlow or SharedFlow within your architecture. Combine this with repeatOnLifecycle to ensure Flow collection only occurs during active lifecycle states, preventing unnecessary background processing.

How do I inject CoroutineDispatcher for testable Android coroutines?

Inject CoroutineDispatcher into your repositories and ViewModels rather than hardcoding it. This allows you to swap in a TestDispatcher during unit tests, enabling deterministic testing with runTest for your asynchronous programming logic.

Does structured concurrency work with Android lifecycleScope for background processing?

Structured concurrency works directly with lifecycleScope to bind background processing to component lifecycles. This guarantees that coroutines launched for data loading are properly cancelled when the lifecycle owner is destroyed.

Why does my Android coroutine crash when touching the UI from a background thread?

Android coroutine crashes occur when UI updates happen off the main thread. Enforce main-safety by injecting CoroutineDispatcher for background work and switching back to the main dispatcher before updating UI state streams.

Can I use Kotlin coroutines for lifecycle-aware data loading across Android architecture layers?

Use Kotlin coroutines for lifecycle-aware data loading by applying structured concurrency across ViewModels, Repositories, and the Data layer. This standardizes asynchronous programming and ensures proper cancellation semantics throughout your app.