Back stack e deep link
Controlli la cronologia e apra route dagli URL.
Back stack e deep link è una lezione Jetpack Compose Academy gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Jetpack Compose Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Jetpack Compose Academy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
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. 🚀
Domande Frequenti
La lezione «Back stack e deep link» è gratuita?
Sì — il testo completo di «Back stack e deep link» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Jetpack Compose Academy, passa a CoddyKit PRO. Il corso Jetpack Compose Academy include 4 lezioni in totale.
Cosa imparerò in «Back stack e deep link»?
Controlli la cronologia e apra route dagli URL. Eserciti Jetpack Compose Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Jetpack Compose Academy?
Non è richiesta alcuna esperienza precedente. Jetpack Compose Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.
Quanto tempo richiede la lezione «Back stack e deep link»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Jetpack Compose Academy?
Sì. Ogni lezione Jetpack Compose Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- NavController e NavHost
- Destinazioni e route Composable
- Passare argomenti tra le schermate
- Back stack e deep link