tezvyn:

What is the difference between viewModelScope and lifecycleScope?

Source: developer.android.combeginner

This tests scope ownership across configuration changes. viewModelScope survives rotation because it lives in ViewModel, while lifecycleScope dies with UI; use former for logic and latter for UI tasks. Never launch data loads in lifecycleScope.

This tests whether you understand coroutine lifecycle boundaries and configuration change survival in the UI layer. viewModelScope is bound to a ViewModel and only cancels when the ViewModel is cleared, making it ideal for business logic that must survive rotation. lifecycleScope is bound to a LifecycleOwner such as an Activity or Fragment and cancels when that lifecycle is destroyed, so it is appropriate for UI-specific animations or one-shot events.

Read the original → developer.android.com

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

What is the difference between viewModelScope and lifecycleScope? · Tezvyn