Recall & Review
beginner
What does the
launch builder do in Kotlin coroutines?The
launch builder starts a new coroutine that runs concurrently without blocking the current thread. It is used for tasks that don't return a result.Click to reveal answer
beginner
What is the main difference between
launch and async builders?launch starts a coroutine that does not return a result, while async starts a coroutine that returns a Deferred result which can be awaited.Click to reveal answer
beginner
How do you get the result from an
async coroutine?You call the
await() function on the Deferred object returned by async to get the result once the coroutine completes.Click to reveal answer
beginner
Why should you avoid blocking the main thread in Android apps?
Blocking the main thread freezes the UI, making the app unresponsive. Using coroutines with
launch or async helps run tasks asynchronously to keep the UI smooth.Click to reveal answer
intermediate
What happens if you call
launch inside a CoroutineScope?A new coroutine starts immediately within that scope and runs concurrently. It inherits the scope's context and lifecycle, so it cancels if the scope is cancelled.
Click to reveal answer
Which builder should you use to start a coroutine that returns a result?
✗ Incorrect
async returns a Deferred result that you can await().What does
launch return when called?✗ Incorrect
launch returns a Job representing the coroutine's lifecycle.How do you wait for the result of an
async coroutine?✗ Incorrect
await() suspends until the result is ready and returns it.Which coroutine builder is best for fire-and-forget tasks?
✗ Incorrect
launch is used for tasks that don't return a result and run concurrently.What happens if you call
await() on a Deferred that is not completed yet?✗ Incorrect
await() suspends the coroutine without blocking the thread until the result is ready.Explain how
launch and async builders differ and when to use each in Android development.Think about whether you need a result or just want to run code concurrently.
You got /4 concepts.
Describe how to get a result from an
async coroutine and why blocking the main thread is bad.Consider how Android apps stay smooth while doing background work.
You got /4 concepts.