Android Basic Interview Revision

Abhinay Gupta
5 min readSep 19, 2024

All my articleas are available for free to read. Here’s the link to this one.

Coroutine context:

  • What thread to run it on.
  • Dispatchers (IO/main/deafault) are used to define the coroutine context.
  • Dispatchers basically dispatch the coroutine to a certain thread.

Suspending functions:

  • Coroutines allow you suspend functionality and later resume at specific points without blocking the thread.
  • Suspending functions allow coroutines to suspend at certain points and later resume from that point onwards.
  • For example, if we have a create user network call, we suspend the function while the network call is in progress and free up the thread and later resume it once the response is received.

Launch vs. async:

  • Launch is used to launch a coroutine and returns a job instance. If we want to wait until that coroutine is done with its work before executing the remaining instructions, we get the job instance and use job.join().
  • When we are expecting an output or a result from a coroutine, we use async. Async returns a deferred object which is a generic type and uses the return type of the last statement in the async block. To wait for async result, we do job.await().
  • We use launch when we don’t care about the result/there isn’t any and async when we expect…

--

--

Abhinay Gupta
Abhinay Gupta

Written by Abhinay Gupta

Exploring personal growth, tech, and culture through engaging storytelling | Inspiring and connecting with readers worldwide.