0Pricing
Jetpack Compose Academy · Lesson

LaunchedEffect for Coroutines

Start suspend work tied to composition.

LaunchedEffect for Coroutines is a free Jetpack Compose Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Jetpack Compose Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Effects Live Outside Composition

Composables should be pure and run many times. When you need to do real work like a network call, you reach for a side effect handler instead.

Meet LaunchedEffect

A LaunchedEffect runs suspend code in a coroutine that is tied to where it sits in your composition. Perfect for one-shot startup work. 🚀

It Starts When It Enters

When a LaunchedEffect first enters the composition, it launches its block. When it leaves the composition, the coroutine is cancelled for you.

LaunchedEffect(Unit) {
    loadProfile()
}

The Key Controls Restarts

The first argument is a key. If the key changes between recompositions, the old coroutine is cancelled and a fresh one starts.

LaunchedEffect(userId) {
    user = fetchUser(userId)
}

Use Unit to Run Once

Passing Unit (or true) as the key means the effect never restarts. It runs a single time when the Composable appears.

LaunchedEffect(Unit) {
    analytics.logScreenView()
}

Suspend Calls Are Welcome

Inside the block you can freely call suspend functions like delay or a Retrofit request. The coroutine scope is provided for you.

LaunchedEffect(Unit) {
    delay(2000)
    showSplash = false
}

Never Launch in the Body

Calling a coroutine directly in the Composable body is a bug. The body re-runs on every recomposition, so you would fire the work again and again.

Cancellation Is Automatic

When the user navigates away and the Composable leaves the screen, Compose cancels the coroutine. No manual cleanup, no leaks.

Pair It with State

Effects usually write their result into state so the UI redraws. Store the loaded data, and recomposition shows it.

var data by remember { mutableStateOf<List<Item>>(emptyList()) }
LaunchedEffect(Unit) { data = repo.load() }

Multiple Keys for Combined Triggers

You can pass several keys. The effect restarts whenever any of them changes, which is handy for re-fetching on filter changes.

LaunchedEffect(query, sort) {
    results = search(query, sort)
}

A Typical Loading Pattern

Together it reads like a recipe: set loading true, await the result, then store it. Compose handles the lifecycle around your coroutine.

LaunchedEffect(id) {
    loading = true
    item = repo.get(id)
    loading = false
}

Quick Check

Think about how restarts are controlled.

Recap: LaunchedEffect

Nice work! LaunchedEffect runs suspend code tied to composition, restarts when its key changes, and cancels itself automatically when the Composable leaves. 🎯

Frequently asked questions

Is the “LaunchedEffect for Coroutines” lesson free?

Yes — the full text of “LaunchedEffect for Coroutines” is free to read here on the web, and the Jetpack Compose Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Jetpack Compose Academy course, upgrade to CoddyKit PRO.

What will I learn in “LaunchedEffect for Coroutines”?

Start suspend work tied to composition. You practise Jetpack Compose Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Jetpack Compose Academy?

No prior experience is required. Jetpack Compose Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “LaunchedEffect for Coroutines” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Jetpack Compose Academy lesson?

Yes. Every Jetpack Compose Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. LaunchedEffect for Coroutines
  2. rememberCoroutineScope for Events
  3. DisposableEffect & Cleanup
  4. derivedStateOf & snapshotFlow
← Back to Jetpack Compose Academy