What problem does it solve?
Android apps often suffer from unsafe coroutine usage, lifecycle leaks, and unstructured concurrency. This skill provides authoritative rules and patterns to write robust, lifecycle-aware Kotlin Coroutines for Android, ensuring structured concurrency and modern best practices.
Core Features & Use Cases
- Structured concurrency enforcement across ViewModel, Repository, and Worker boundaries to prevent leaks.
- Lifecycle integration with viewModelScope, lifecycleScope, and repeatOnLifecycle for safe flow collection.
- Reactive streams support with Flow, StateFlow, SharedFlow, and callbackFlow for responsive UIs.
- Error handling, cancellation, and testing patterns (CoroutineExceptionHandler, TestDispatcher, runTest) to improve reliability.
- Guidance to avoid hard-coding Dispatchers and to maintain main-safety across layers.
Quick Start
Refactor a sample Android feature to inject a CoroutineDispatcher and expose UI state via StateFlow in a ViewModel. Demonstrate lifecycle-safe collection using repeatOnLifecycle and viewModelScope for long-running tasks.