Android Coroutines & Flow Interview Questions

Concurrency, structured scopes, and reactive streams.

50 questions in this topic · 8 sample questions below

Practice Coroutines & Flow in the quiz engine

Sample questions

  1. Inside a coroutineScope block, one of two child coroutines launched with launch throws an exception. What happens to the sibling coroutine and the coroutineScope call?

    • The sibling is cancelled and coroutineScope rethrows the exception — correct
    • The sibling keeps running and coroutineScope returns normally
    • Only the failing child is cancelled; coroutineScope swallows the exception
    • The exception is delivered to a CoroutineExceptionHandler and both children continue

    Why: coroutineScope uses a regular Job, so a child failure cancels all siblings and the exception is rethrown by coroutineScope. It is not swallowed, and a handler is irrelevant because coroutineScope propagates by throwing, not by invoking an exception handler.

  2. You wrap a launch call in a try/catch block. A coroutine started by that launch throws inside its body. Does the surrounding try/catch catch it?

    • Yes, because launch runs synchronously up to the first suspension
    • No, launch returns immediately and the exception surfaces through the Job hierarchy, not the caller — correct
    • Yes, but only if the exception is thrown before the first suspension point
    • No, unless you also add a CoroutineExceptionHandler to the same try/catch

    Why: launch returns a Job immediately and runs the body asynchronously, so exceptions propagate up the coroutine hierarchy rather than to the launching code's try/catch. Wrapping launch in try/catch never catches the child's exception, even for pre-suspension throws, because the body is scheduled, not invoked inline in the general case.

  3. A CoroutineExceptionHandler is installed in the context of a child coroutine created with launch. An uncaught exception occurs in that child. Is the handler invoked?

    • Yes, the handler nearest to where the exception occurred is used
    • Yes, but only if the child used async instead of launch
    • No, only a handler installed on the root/scope coroutine is used for uncaught exceptions — correct
    • No, CoroutineExceptionHandler only works with supervisorScope

    Why: CoroutineExceptionHandler is only honored when installed on the scope or the root coroutine that becomes responsible for the exception; a handler on an inner child is ignored because the exception propagates upward first. It is not tied to async or supervisorScope specifically.

  4. What is the key difference between withContext(Dispatchers.IO) and async(Dispatchers.IO) for a single unit of work whose result you need immediately?

    • withContext runs the block concurrently while async runs it sequentially
    • They are identical; withContext is just sugar for async().await()
    • async blocks the current thread until completion while withContext does not
    • withContext suspends and returns the result directly, running the block sequentially in place; async starts a concurrent job returning a Deferred — correct

    Why: withContext switches context, runs the block, suspends until it finishes, and returns the value directly, so it is sequential. async is for concurrency: it returns a Deferred you await later, which is wasteful when you need the result immediately and would only add overhead.

  5. A tight CPU-bound while(true) loop runs inside a coroutine. You cancel the coroutine's Job. What happens?

    • The loop keeps running; cancellation is cooperative and the loop never checks for it — correct
    • The loop stops immediately because cancellation interrupts the thread
    • The loop throws CancellationException at the next arithmetic operation
    • The loop is paused and resumes if the Job is un-cancelled

    Why: Cancellation is cooperative: a coroutine only becomes cancelled when it suspends at a cancellable point or explicitly checks isActive/ensureActive. A pure CPU loop with no suspension or checks ignores cancellation entirely, so it does not stop automatically.

  6. Which statement about a StateFlow's initial value is correct?

    • StateFlow always starts empty and has no initial value
    • MutableStateFlow requires an initial value passed to its constructor — correct
    • The initial value is supplied lazily on first collection
    • You must call emit once before any collector attaches

    Why: MutableStateFlow(initialValue) mandates an initial value, so a StateFlow always has a current value available synchronously. It is never empty and does not wait for a collector, unlike a plain cold Flow.

  7. You set the same data class value into a MutableStateFlow twice in a row where the value equals the current value. How many emissions do collectors observe?

    • Two emissions, one per assignment
    • Two, because StateFlow never deduplicates
    • Zero or one; StateFlow conflates and deduplicates using equals, so an equal value is not re-emitted — correct
    • One only if the object reference is identical, using referential equality

    Why: StateFlow deduplicates using equals(): setting a value equal to the current one produces no new emission. It uses structural equality, not referential identity, so equal data class instances are treated as no change.

  8. In a supervisorScope, a child launched with launch fails with an exception. What is the effect on its sibling coroutines?

    • All siblings are cancelled, same as coroutineScope
    • The whole supervisorScope is cancelled but siblings finish their current step
    • Siblings are cancelled only if they share the same dispatcher
    • Siblings continue running; failure does not propagate upward to cancel them — correct

    Why: supervisorScope uses a SupervisorJob so a child's failure is isolated and does not cancel siblings or the scope. This is the opposite of coroutineScope, where any child failure cancels all others.

Practice all 50 Coroutines & Flow questions

These 8 are a sample. The full Coroutines & Flow bank is scored, tracks your progress, and explains every answer.

Open the quiz

More Android interview topics