Execution Order in Jetpack Compose Explained with Analogies

Understanding when LaunchedEffect, DisposableEffect, and composables run in Jetpack Compose can be tricky. Let’s simplify with a few real-world analogies.

🎭 Composables = Stage Actors

Composables are like actors:

🕯️ LaunchedEffect = Candle in a Room

🧹 DisposableEffect = Hotel Housekeeping

🔄 Recomposition = Changing Actor’s Lines

If the script (state) changes, actors stay on stage but adjust their lines. No need to re-run effects unless keys change.

Quick Comparison

Concept Analogy When It Runs When It Cleans Up
Composable Actor On screen draw/state On removal
LaunchedEffect Candle On enter/key change On key change/removal
DisposableEffect Housekeeping On enter/key change On key change/removal

✅ Final Tip

So next time you add a LaunchedEffect or a DisposableEffect, ask yourself: