Back Stack & Deep Links
Control history and open routes from URLs.
Back Stack & Deep Links is a free Jetpack Compose Academy lesson on CoddyKit — lesson 4 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.
What the Back Stack Is
The back stack is the history of screens you have visited. Each navigate call pushes a new entry on top of it.
Going Back
Calling popBackStack() removes the top entry and shows the screen beneath. The system back gesture does the same thing automatically.
navController.popBackStack()Pop Up To a Route
Use popUpTo while navigating to clear screens off the stack up to a target. It is perfect for returning to a known root.
navController.navigate("home") {
popUpTo("home")
}Avoid Duplicate Entries
Set launchSingleTop to true so tapping the same destination twice does not stack identical copies of it.
navController.navigate("home") {
launchSingleTop = true
}Clear After Login
After signing in, pop the login screen with inclusive = true so back never returns to it.
navController.navigate("home") {
popUpTo("login") { inclusive = true }
}Meet Deep Links
A deep link opens a specific screen directly from a URL or notification, skipping the normal step-by-step path through your app.
Declare a Deep Link
Attach a navDeepLink to a destination with a URI pattern. Compose matches incoming links against that pattern.
composable(
"profile/{userId}",
deepLinks = listOf(navDeepLink { uriPattern = "app://profile/{userId}" })
) { }Deep Links Carry Arguments
Placeholders in a deep link URI fill your route arguments. Opening app://profile/42 lands on the profile screen with userId set to 42.
Register an Intent Filter
For links from outside the app, add a matching intent-filter in the manifest so Android routes the URL to your activity.
Deep Links Build the Stack
Navigation Compose can synthesize a back stack for a deep link, so pressing back walks up to a sensible parent instead of exiting.
Observe the Current Entry
Collect currentBackStackEntryAsState to react to where the user is, useful for highlighting a selected tab.
val entry by navController.currentBackStackEntryAsState()
val route = entry?.destination?.routeQuick Check
How do you stop back from returning to the login screen?
Recap
You now control history with popUpTo and launchSingleTop, and you can jump straight to a screen using deep links that even rebuild a sensible back stack. 🚀
Frequently asked questions
Is the “Back Stack & Deep Links” lesson free?
Yes — the full text of “Back Stack & Deep Links” 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 “Back Stack & Deep Links”?
Control history and open routes from URLs. 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 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Back Stack & Deep Links” 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
- NavController & NavHost
- Composable Destinations & Routes
- Passing Arguments Between Screens
- Back Stack & Deep Links