Why viewModelScope.launch(SupervisorJob()) Still Crashes Your App

Orange balloon drifting away with its string hanging loose, representing a coroutine detached from viewModelScope by launch(SupervisorJob())

Passing SupervisorJob() to launch in viewModelScope doesn’t stop a crash, and it detaches the coroutine from onCleared(). Here’s the two-bug reason, a runnable repro, the fix, and the interview answer.

Why Wrapping a Suspend Function in withContext(Dispatchers.IO) Is Usually a Mistake

Rows of colored thread spools, representing Kotlin coroutine dispatchers and threads in a withContext(Dispatchers.IO) call

Kotlin’s suspend functions carry an implicit promise. A main-safe suspend function takes care of its own threading, no matter who calls it. In real codebases, callers break that promise constantly. A common defensive habit is wrapping every call that might touch disk or network in withContext(Dispatchers.IO). Developers do it even when the function being called … Read more