More on Constructing a Coroutine Scope

Learn how to use viewModelScope and lifecycleScope, create a coroutine, and create a scope for additional calls.

viewModelScope and lifecycleScope

In modern Android applications, instead of defining our own scope, we can also use viewModelScope or lifecycleScope. They work almost identically to what we’ve just constructed. They use Dispatchers.Main and SupervisorJob, and they cancel the job when the view model or lifecycle owner gets destroyed.

Get hands-on with 1200+ tech skills courses.