Pilha de Retorno e Links Profundos
Controle o histórico e abra rotas a partir de URLs.
Pilha de Retorno e Links Profundos é uma aula grátis de Jetpack Compose Academy no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Jetpack Compose Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Jetpack Compose Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
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. 🚀
Perguntas Frequentes
A aula “Pilha de Retorno e Links Profundos” é grátis?
Sim — o texto completo de “Pilha de Retorno e Links Profundos” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Jetpack Compose Academy, atualize para CoddyKit PRO. O curso de Jetpack Compose Academy inclui 4 aulas no total.
O que vou aprender em “Pilha de Retorno e Links Profundos”?
Controle o histórico e abra rotas a partir de URLs. Você pratica Jetpack Compose Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Jetpack Compose Academy?
Nenhuma experiência prévia é necessária. Jetpack Compose Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.
Quanto tempo leva a aula “Pilha de Retorno e Links Profundos”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Jetpack Compose Academy?
Sim. Cada aula de Jetpack Compose Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- NavController e NavHost
- Destinos e Rotas Composable
- Passando Argumentos entre Telas
- Pilha de Retorno e Links Profundos