Android

Kotlin Coroutines and Flow

Asynchronous programming with Coroutines: launch, async, suspend functions, Dispatchers, Flow, StateFlow, SharedFlow

20 питань зі співбесід·
Mid-Level
1

What is a coroutine in Kotlin?

Відповідь

A coroutine is a lightweight thread that allows writing asynchronous code sequentially. It can be suspended without blocking the thread, allowing other tasks to execute. More efficient than traditional threads.

2

What is the difference between launch and async?

Відповідь

launch starts a coroutine that doesn't return a result (returns a Job). async starts a coroutine that returns a result via a Deferred (await()). Use async when you need the result.

3

What is the suspend keyword used for?

Відповідь

suspend marks a function that can be suspended and resumed later without blocking the thread. These functions can only be called from other suspend functions or coroutines. They enable asynchronous operations.

4

What is a Dispatcher in coroutines?

5

When to use Dispatchers.IO?

+17 питань зі співбесід

Опануй Android для наступної співбесіди

Отримай доступ до всіх питань, flashcards, технічних тестів, вправ code review та симуляторів співбесід.

Почни безкоштовно