Which side-effect handler for a one-time coroutine on composition entry?

Tests Compose side-effect API boundaries. Answer: LaunchedEffect(Unit); it runs once and auto-cancels on exit. Contrast with rememberCoroutineScope for user-triggered callbacks. Red flag: picking SideEffect or rememberCoroutineScope and missing cancellation.
Tests whether you can match Compose side-effect APIs to lifecycle needs. A strong answer names LaunchedEffect(Unit) with an unchanging key so the coroutine launches exactly once on entry and auto-cancels on exit. Distinguish this from rememberCoroutineScope, which is for user-triggered actions like button clicks, and from SideEffect, which runs synchronously on every recomposition. LaunchedEffect provides the CoroutineScope and respects composition lifecycle.
Read the original → developer.android.com
- #android
- #jetpack-compose
- #side-effects
- #coroutines
- #intermediate
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.