No. Avoid `GlobalScope` in a `ViewModel`: it is not tied to the `ViewModel` lifecycle, so work can continue after the `ViewModel` is cleared and may leak or update stale state. Use `viewModelScope`, which cancels its children when the `ViewModel` is cleared: ```kotlin class ItemsViewModel( private val repository: ItemsRepository, ) : ViewModel() { fun loadItems() { viewModelScope.launch { repository.loadItems() } } } ``` Keep dispatcher selection injectable in the repository or use case rathe...
Scanned 9/5/2026
Install to Claude Code
npx -y skills add HoangNguyen0403/agent-skills-standard --skill android-concurrency --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Android Concurrency?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-android-concurrency-agent-skills-standard)More formats (shields.io, HTML) on the badges page.
No. Avoid `GlobalScope` in a `ViewModel`: it is not tied to the `ViewModel` lifecycle, so work can continue after the `ViewModel` is cleared and may leak or update stale state.
Use `viewModelScope`, which cancels its children when the `ViewModel` is cleared:
```kotlin
class ItemsViewModel(
private val repository: ItemsRepository,
) : ViewModel() {
fun loadItems() {
viewModelScope.launch {
repository.loadItems()
}
}
}
```
Keep dispatcher selection injectable in the repository or use case rather than hardcoding `Dispatchers.IO`:
```kotlin
suspend fun loadItems() = withContext(dispatchers.io) {
api.fetchItems()
}
```
Use `lifecycleScope` for Activity/Fragment work. These lifecycle-bound scopes preserve structured concurrency and make cancellation predictable.
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!