AceMobileInterview

Android track

General topic questions

Coroutines & Dispatchers

MediumMost asked

Free section · general topics & algorithms

How do Dispatchers.Main, IO, and Default differ? How do you structure structured concurrency in a ViewModel?

Reveal model answer
Main for UI, IO for blocking I/O, Default for CPU work. viewModelScope cancels on clear. Prefer withContext for thread switches, supervisorScope when children should fail independently, and never leak GlobalScope. Expose UI state via StateFlow.
Activity & process lifecycleDerivedStateOf