kotlin-concurrency-expert

Review Kotlin Coroutines usage in Android apps for lifecycle safety and dispatcher optimization.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses complex concurrency issues in Kotlin/Android applications, ensuring robust, efficient, and lifecycle-aware asynchronous operations.

Core Features & Use Cases

  • Coroutine Review & Debugging: Analyzes and fixes bugs related to coroutines, ANRs, and memory leaks.
  • Lifecycle Safety: Implements structured concurrency and proper scoping to prevent coroutine leaks.
  • Performance Optimization: Improves thread safety and resolves issues with dispatcher usage.
  • Use Case: A developer is experiencing ANRs in their Android app due to blocking the main thread. This Skill can identify the offending coroutine, refactor it to use Dispatchers.IO, and ensure it's properly scoped to the ViewModel's lifecycle.

Quick Start

Review the provided Kotlin code for lifecycle-related coroutine issues and suggest improvements.

Frequently Asked Questions about kotlin-concurrency-expert

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

FAQPage Schema
How do I fix ANRs in my Android app caused by blocking the main thread with Kotlin coroutines?

To fix ANRs caused by Kotlin coroutines, you must move blocking operations off the main thread by refactoring them to use Dispatchers.IO. Ensure the coroutine is properly scoped to the ViewModel's lifecycle to prevent leaks.

What is the best way to prevent memory leaks when using Kotlin coroutines in Android?

The best way to prevent memory leaks with Kotlin coroutines is to apply structured concurrency and proper lifecycle scoping. Using viewModelScope and repeatOnLifecycle ensures coroutines are automatically cancelled when their lifecycle owner is destroyed.

How do I optimize dispatcher usage for thread safety in Android coroutines?

Optimize dispatcher usage for thread safety by applying proper dispatcher injection and ensuring coroutines run on the correct threads. Review your code to resolve dispatcher issues and improve overall asynchronous performance.

Does viewModelScope work with repeatOnLifecycle for structured concurrency in Android?

Yes, viewModelScope works with repeatOnLifecycle to enforce structured concurrency in Android. This combination ensures that asynchronous operations are properly scoped and safely suspended according to the Fragment or Activity lifecycle.

Why does my Kotlin coroutine keep running after the Android Fragment is destroyed?

Your Kotlin coroutine keeps running because it lacks proper lifecycle safety and structured concurrency. Without repeatOnLifecycle scoping, the coroutine is not cancelled when the Fragment is destroyed, leading to potential memory leaks.

Kotlin coroutines not working correctly in my Android app, what are common lifecycle safety limitations?

Common lifecycle safety limitations include improper scoping and blocking the main thread. Without structured concurrency practices like viewModelScope and repeatOnLifecycle, coroutines can cause ANRs, memory leaks, and thread safety issues.