tezvyn:

Which Compose side-effect for a one-time coroutine action?

Source: developer.android.comintermediate

Tests if you can choose the right Compose side-effect for a one-time coroutine. A great answer names `LaunchedEffect(Unit)`, explains it runs once and cancels on exit. A red flag is suggesting `rememberCoroutineScope` directly in the composable body.

This tests your knowledge of Compose's side-effect handlers and their lifecycle awareness. A strong answer identifies `LaunchedEffect(Unit)` as the correct choice, explaining that the `Unit` key ensures the coroutine runs only once on initial composition and is automatically cancelled when the composable leaves the screen. A major red flag is suggesting `rememberCoroutineScope` to launch a new coroutine on every recomposition, which causes a resource storm.

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.

Which Compose side-effect for a one-time coroutine action? · Tezvyn