Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
new-silvermoon avatar

Android Coroutines

  • 438 installs
  • 910 repo stars
  • Updated July 27, 2026
  • new-silvermoon/awesome-android-agent-skills

android-coroutines is an agent skill that applies production Kotlin Coroutines patterns—structured concurrency, lifecycle integration, Flow, and StateFlow—for developers building non-blocking Android network, database, a

About

android-coroutines is an Android agent skill from new-silvermoon/awesome-android-agent-skills that encodes authoritative Kotlin Coroutines rules for production mobile apps. It guides suspend functions, Dispatcher selection, parallel execution, structured concurrency, and lifecycle-safe job scoping so network calls, Room or database IO, and UI updates never block threads or leak coroutines. The skill also covers reactive streams—Flow, StateFlow, SharedFlow, and callbackFlow—for modern Android state management aligned with 2025 best practices. Developers reach for android-coroutines when implementing async Android features and need agents to follow consistent coroutine scoping, cancellation, and lifecycle integration instead of ad hoc threading. It complements Jetpack lifecycle components by enforcing patterns that prevent memory leaks from unstructured GlobalScope usage and orphaned jobs during configuration changes or destroyed Activities.

  • Structured concurrency scopes
  • Flow collection in UI
  • Cancellation-safe jobs
  • Main-safe dispatchers
  • Repository async patterns

Android Coroutines by the numbers

  • 438 all-time installs (skills.sh)
  • +16 installs in the week ending Aug 4, 2026 (Skillselion tracking)
  • Ranked #325 of 1,039 Mobile Development skills by installs in the Skillselion catalog
  • Data as of Aug 4, 2026 (Skillselion catalog sync)
npx skills add https://github.com/new-silvermoon/awesome-android-agent-skills --skill android-coroutines

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs438
repo stars910
Last updatedJuly 27, 2026
Repositorynew-silvermoon/awesome-android-agent-skills

How do you write production Android coroutines safely?

Implement async Android work with coroutines for network calls, database IO, and UI updates without blocking threads or leaking jobs.

Who is it for?

Android developers writing Kotlin apps who need agents to enforce structured concurrency, Flow streams, and lifecycle-bound coroutine scopes.

Skip if: iOS Swift concurrency work or backend-only Kotlin services with no Android lifecycle concerns.

When should I use this skill?

User asks to add async network calls, database IO, Flow state, or coroutine refactors on an Android Kotlin codebase.

What you get

Lifecycle-scoped suspend functions, Flow collectors, Dispatcher usage, and coroutine patterns without thread leaks or orphaned jobs.

  • suspend function implementations
  • Flow-based state holders
  • lifecycle-scoped coroutine code

By the numbers

  • Covers 4 reactive stream types: Flow, StateFlow, SharedFlow, and callbackFlow

Files

SKILL.mdMarkdownGitHub ↗

Android Coroutines Expert Skill

This skill provides authoritative rules and patterns for writing production-quality Kotlin Coroutines code on Android. It enforces structured concurrency, lifecycle safety, and modern best practices (2025 standards).

Responsibilities

  • Asynchronous Logic: Implementing suspend functions, Dispatcher management, and parallel execution.
  • Reactive Streams: Implementing Flow, StateFlow, SharedFlow, and callbackFlow.
  • Lifecycle Integration: Managing scopes (viewModelScope, lifecycleScope) and safe collection (repeatOnLifecycle).
  • Error Handling: Implementing CoroutineExceptionHandler, SupervisorJob, and proper try-catch hierarchies.
  • Cancellability: Ensuring long-running operations are cooperative using ensureActive().
  • Testing: Setting up TestDispatcher and runTest.

Applicability

Activate this skill when the user asks to:

  • "Fetch data from an API/Database."
  • "Perform background processing."
  • "Fix a memory leak" related to threads/tasks.
  • "Convert a listener/callback to Coroutines."
  • "Implement a ViewModel."
  • "Handle UI state updates."

Critical Rules & Constraints

1. Dispatcher Injection (Testability)

  • NEVER hardcode Dispatchers (e.g., Dispatchers.IO, Dispatchers.Default) inside classes.
  • ALWAYS inject a CoroutineDispatcher via the constructor.
  • DEFAULT to Dispatchers.IO in the constructor argument for convenience, but allow it to be overridden.
// CORRECT
class UserRepository(
    private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
) { ... }

// INCORRECT
class UserRepository {
    fun getData() = withContext(Dispatchers.IO) { ... }
}

2. Main-Safety

  • All suspend functions defined in the Data or Domain layer must be main-safe.
  • One-shot calls should be exposed as suspend functions.
  • Data changes should be exposed as Flow.
  • The caller (ViewModel) should be able to call them from Dispatchers.Main without blocking the UI.
  • Use withContext(dispatcher) inside the repository implementation to move execution to the background.

3. Lifecycle-Aware Collection

  • NEVER collect a flow directly in lifecycleScope.launch or launchWhenStarted (deprecated/unsafe).
  • ALWAYS use repeatOnLifecycle(Lifecycle.State.STARTED) for collecting flows in Activities or Fragments.
// CORRECT
viewLifecycleOwner.lifecycleScope.launch {
    viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
        viewModel.uiState.collect { ... }
    }
}

4. ViewModel Scope Usage

  • Use viewModelScope for initiating coroutines in ViewModels.
  • Do not expose suspend functions from the ViewModel to the View. The ViewModel should expose StateFlow or SharedFlow that the View observes.

5. Mutable State Encapsulation

  • NEVER expose MutableStateFlow or MutableSharedFlow publicly.
  • Expose them as read-only StateFlow or Flow using .asStateFlow() or upcasting.

6. GlobalScope Prohibition

  • NEVER use GlobalScope. It breaks structured concurrency and leads to leaks.
  • If a task must survive the current scope, use an injected applicationScope (a custom scope tied to the Application lifecycle).

7. Exception Handling

  • NEVER catch CancellationException in a generic catch (e: Exception) block without rethrowing it.
  • Use runCatching only if you explicitly rethrow CancellationException.
  • Use CoroutineExceptionHandler only for top-level coroutines (inside launch). It has no effect inside async or child coroutines.

8. Cancellability

  • Coroutines feature cooperative cancellation. They don't stop immediately unless they check for cancellation.
  • ALWAYS call ensureActive() or yield() in tight loops (e.g., processing a large list, reading files) to check for cancellation.
  • Standard functions like delay() and withContext() are already cancellable.

9. Callback Conversion

  • Use callbackFlow to convert callback-based APIs to Flow.
  • ALWAYS use awaitClose at the end of the callbackFlow block to unregister listeners.

Code Patterns

Repository Pattern with Flow

class NewsRepository(
    private val remoteDataSource: NewsRemoteDataSource,
    private val externalScope: CoroutineScope, // For app-wide events
    private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
) {
    val newsUpdates: Flow<List<News>> = flow {
        val news = remoteDataSource.fetchLatestNews()
        emit(news)
    }.flowOn(ioDispatcher) // Upstream executes on IO
}

Parallel Execution

suspend fun loadDashboardData() = coroutineScope {
    val userDeferred = async { userRepo.getUser() }
    val feedDeferred = async { feedRepo.getFeed() }
    
    // Wait for both
    DashboardData(
        user = userDeferred.await(),
        feed = feedDeferred.await()
    )
}

Testing with runTest

@Test
fun testViewModel() = runTest {
    val testDispatcher = StandardTestDispatcher(testScheduler)
    val viewModel = MyViewModel(testDispatcher)
    
    viewModel.loadData()
    advanceUntilIdle() // Process coroutines
    
    assertEquals(expectedState, viewModel.uiState.value)
}

Related skills

How it compares

Pick android-coroutines for Kotlin mobile async patterns; use generic Android architecture skills when the task is navigation or Compose layout structure instead of concurrency.

FAQ

What reactive types does android-coroutines cover?

android-coroutines covers Flow, StateFlow, SharedFlow, and callbackFlow for Android reactive streams alongside suspend functions and Dispatcher management. The skill applies these patterns with lifecycle integration and structured concurrency rules.

When should android-coroutines activate?

android-coroutines activates when implementing asynchronous Android logic such as network requests, database IO, or UI state updates with Kotlin Coroutines. It enforces production patterns that avoid blocking threads and leaking jobs across lifecycle events.

Mobile Developmentfrontendbackend

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.