0
0
Android Kotlinmobile~5 mins

CoroutineScope and dispatchers in Android Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a CoroutineScope in Kotlin coroutines?
A CoroutineScope defines the lifecycle for coroutines. It controls when coroutines start and when they are cancelled, helping manage background work safely.
Click to reveal answer
beginner
Name the main types of Dispatchers in Kotlin coroutines.
The main dispatchers are:<br>• Dispatchers.Main - runs on the main thread (UI thread)<br>• Dispatchers.IO - optimized for disk or network I/O<br>• Dispatchers.Default - for CPU-intensive work<br>• Dispatchers.Unconfined - starts coroutine in current thread but can resume in another
Click to reveal answer
beginner
Why use Dispatchers.IO for network or disk operations?
Dispatchers.IO uses a shared pool of threads optimized for blocking I/O tasks. This keeps the main thread free and prevents UI freezes.
Click to reveal answer
intermediate
What happens if you launch a coroutine without specifying a dispatcher?
It inherits the dispatcher from its CoroutineScope. If the scope uses Dispatchers.Main, the coroutine runs on the main thread by default.
Click to reveal answer
intermediate
Explain the role of CoroutineScope in managing coroutine lifecycles.
CoroutineScope ties coroutines to a lifecycle, like an Activity or ViewModel. When the scope is cancelled, all coroutines inside it are also cancelled, preventing memory leaks.
Click to reveal answer
Which dispatcher should you use for updating the UI in Android?
ADispatchers.Default
BDispatchers.IO
CDispatchers.Main
DDispatchers.Unconfined
What does CoroutineScope control?
AThe speed of coroutines
BThe memory usage of coroutines
CThe number of threads used
DThe lifecycle and cancellation of coroutines
Which dispatcher is best for CPU-intensive tasks?
ADispatchers.IO
BDispatchers.Default
CDispatchers.Main
DDispatchers.Unconfined
What happens when a CoroutineScope is cancelled?
AAll coroutines in that scope are cancelled
BOnly the first coroutine is cancelled
CCoroutines continue running
DThe app crashes
Which dispatcher starts a coroutine in the current thread but can resume in another?
ADispatchers.Unconfined
BDispatchers.IO
CDispatchers.Default
DDispatchers.Main
Describe how CoroutineScope and dispatchers work together to manage background tasks in Android.
Think about how you keep coroutines organized and where they run.
You got /3 concepts.
    Explain why choosing the right dispatcher is important for app performance and user experience.
    Consider what happens if you do heavy work on the main thread.
    You got /4 concepts.