0
0
Android Kotlinmobile~20 mins

CoroutineScope and dispatchers in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CoroutineScope Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding CoroutineScope context
What is the default dispatcher used by CoroutineScope when none is specified?
ADispatchers.Unconfined
BDispatchers.Default
CDispatchers.Main
DDispatchers.IO
Attempts:
2 left
💡 Hint
Think about the dispatcher optimized for CPU-intensive work.
ui_behavior
intermediate
2:00remaining
Choosing dispatcher for network calls
Which dispatcher should you use to perform network requests without blocking the main thread?
ADispatchers.IO
BDispatchers.Main
CDispatchers.Default
DDispatchers.Unconfined
Attempts:
2 left
💡 Hint
This dispatcher is optimized for blocking IO tasks like file or network operations.
lifecycle
advanced
2:00remaining
CoroutineScope and Android lifecycle
What happens if you launch a coroutine in a CoroutineScope tied to an Activity and the Activity is destroyed before the coroutine completes?
AThe coroutine continues running in the background.
BThe coroutine throws an exception immediately.
CThe coroutine is automatically cancelled.
DThe coroutine switches to Dispatchers.Main automatically.
Attempts:
2 left
💡 Hint
Think about how lifecycle-aware scopes behave to prevent memory leaks.
📝 Syntax
advanced
2:00remaining
Correct dispatcher usage in coroutine launch
Which of the following code snippets correctly launches a coroutine on the IO dispatcher?
Android Kotlin
fun fetchData() {
  CoroutineScope(Dispatchers.IO).launch {
    // network call
  }
}
ACoroutineScope(Dispatchers.IO).launch { /* network call */ }
BCoroutineScope.launch(Dispatchers.IO) { /* network call */ }
CCoroutineScope(Dispatchers.Main).launch(Dispatchers.IO) { /* network call */ }
Dlaunch(Dispatchers.IO) { /* network call */ }
Attempts:
2 left
💡 Hint
Remember how to pass dispatcher to CoroutineScope constructor.
🔧 Debug
expert
2:00remaining
Diagnosing coroutine dispatcher misuse
Given this code snippet, what error or behavior will occur? fun loadData() { CoroutineScope(Dispatchers.Main).launch { Thread.sleep(3000) println("Data loaded") } }
AThe code causes a compile-time error due to Thread.sleep usage.
BThe coroutine throws a CancellationException immediately.
CThe coroutine runs asynchronously without blocking the UI.
DThe UI freezes for 3 seconds because Thread.sleep blocks the main thread.
Attempts:
2 left
💡 Hint
Consider what Thread.sleep does on the main thread.