tezvyn:

How do you make a network request in an Activity using coroutines?

Source: developer.android.combeginner

This tests main thread safety and coroutine dispatchers. A strong answer cites NetworkOnMainThreadException, uses lifecycleScope, and switches to Dispatchers.IO. Red flag: suggesting Dispatchers.Main for the network call or omitting the exception entirely.

This tests whether you understand Android's single main thread model and structured concurrency. A complete answer names the NetworkOnMainThreadException, explains that blocking IO freezes the UI and risks ANRs, and shows a lifecycleScope.launch block that uses withContext(Dispatchers.IO) for the actual request. It should also contrast why Default is for CPU work and Main is for UI updates. Red flags include proposing AsyncTask, raw threads, or running the call on Dispatchers.Main.

Read the original → developer.android.com

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

How do you make a network request in an Activity using coroutines? · Tezvyn