0
0
Kotlinprogramming~5 mins

Dispatchers.Main, IO, Default behavior in Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is Dispatchers.Main used for in Kotlin coroutines?

Dispatchers.Main is used to run coroutines on the main thread, which is the UI thread in Android. It is ideal for updating the UI after background work.

Click to reveal answer
beginner
What kind of tasks should be run with Dispatchers.IO?

Dispatchers.IO is optimized for offloading blocking IO tasks like reading/writing files, network calls, or database operations to a shared pool of threads.

Click to reveal answer
beginner
Explain the role of Dispatchers.Default.

Dispatchers.Default is used for CPU-intensive tasks like sorting, parsing, or complex calculations. It uses a shared pool of threads optimized for such work.

Click to reveal answer
intermediate
What happens if you launch a coroutine without specifying a dispatcher?

By default, the coroutine inherits the dispatcher from its parent or uses Dispatchers.Default if no parent context is available.

Click to reveal answer
beginner
Why should UI updates always be done on Dispatchers.Main?

Because UI frameworks like Android require UI changes to happen on the main thread to avoid crashes and ensure smooth user experience.

Click to reveal answer
Which dispatcher is best for network requests in Kotlin coroutines?
ADispatchers.Main
BDispatchers.IO
CDispatchers.Default
DDispatchers.Unconfined
What thread does Dispatchers.Main use?
ABackground thread pool
BNew thread every time
CMain UI thread
DUnconfined thread
If you launch a coroutine without specifying a dispatcher, which dispatcher is used by default?
ADispatchers.Default
BDispatchers.IO
CNo dispatcher is used
DDispatchers.Main
Which dispatcher is optimized for CPU-intensive tasks?
ADispatchers.Default
BDispatchers.Main
CDispatchers.IO
DDispatchers.Unconfined
Why should you avoid running long blocking tasks on Dispatchers.Main?
AIt will crash the app immediately
BIt uses too many threads
CIt runs too fast
DIt blocks the UI thread causing the app to freeze
Describe the main differences between Dispatchers.Main, Dispatchers.IO, and Dispatchers.Default in Kotlin coroutines.
Think about where each dispatcher runs and what kind of work it is best for.
You got /3 concepts.
    Explain what happens if you launch a coroutine without specifying any dispatcher and why this default behavior is useful.
    Consider how coroutines decide where to run if you don't tell them explicitly.
    You got /3 concepts.