https://kotlinlang.org logo
Join Slack
Channels
announcements
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
akkurate
alexa
algeria
algolialibraries
amper
amsterdam
android
android-architecture
android-databinding
androidgithubprojects
android-studio
androidthings
androidx
androidx-xprocessing
anime
anko
apollo-kotlin
appintro
appyx
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
aws-sdk
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
benchmarks
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chennai
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitivecoding
competitive-programming
compiler
compose
compose-android
compose-desktop
compose-destinations
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
confetti
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cup-presentations
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
dependency-injection
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effectivekotlin
effective-kotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
fleet
flow
flowmvi
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
fun-adaptive
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gsoc-compose-multiplatform-storybook
gsoc-ij-gradle-plugin
gsoc-kmp-bazel
gsoc-kmp-bazel
gsoc-kmp-gemini-firebase
gsoc-kotlin-bom-bazel
gsoc-kotlin-lsp-project
gsoc-kotlin-openrewrite
gsoc-wasm-incremental-compilation
gui
hackathons
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hiring-french
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
j2k
jackson-kotlin
jadx
japanese
jasync-sql
javadevelopers
javafx
javalin
javascript
java-to-kotlin-refactoring
jdbi
jewel
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm
jvm-ir-backend-feedback
jxadapter
k2-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kilua
kinta
klaxon
klibs-io
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-contributors
komapper
kondor-json
kong
konsist
konsist-dev
kontent
kontributors
koog-agentic-framework
korau
kore
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlinacademy
kotlin-asia
kotlin-beam
kotlinbot
kotlin-by-example
kotlinconf
kotlin-csv
kotlin-data-storage
kotlindl
kotlinforbeginners
kotlin-foundation
kotlin-fuel
kotlingforbeginners
kotlin-in-action
kotlin-inject
kotlin-kinetics
kotlin-latam
kotlin-logging
kotlinlondon
kotlinmad
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlinprogrammers
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlinsu
kotlin-szeged
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlin-website
kotlinx-collections-immutable
kotlinx-datetime
kotlinx-files
kotlinx-html
kotlinx-rpc
kotools
kotrix
kotson
kotzilla-platform
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
kstatemachine
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
lincheck
linenbot
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
newname
new-zealand
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
olpaka
oolong
opensavvy
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
parameterize
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
power-assert
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
store
storyboard
storytale
strife-discord-lib
strikt
students
stuttgart
sudan
supabase-kt
swagger-gradle-codegen
swarm
sweden
swift-export
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
terpal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vilnius-kug
vim
vkug
vuejs
webassembly
web-mpp
webrtc
wimix_sentry
wwdc
zircon
Powered by
# navigation-architecture-component
  • v

    Vyshas

    08/02/2021, 8:57 PM
    How do we track bottom menu nav items clicks only when bottom menu items are clicked ? Currently using Bottom navigation view 2.4.0-alpha05, we have a use case for tracking bottom nav clicks for analytics and bottom nav is set like below
    Copy code
    binding.bottomNavigationView.setupWithNavController(navController)
    If I use below, then bottom nav selection stops working.
    Copy code
    binding.bottomNavigationView.setOnItemSelectedListener { 
                //track clicks
    
                true
            }
  • t

    Tepes Lucian Victor

    09/03/2021, 4:11 PM
    I’ve started a new project using navigation component multiple backstack support and i’ve hit an issue with having an auth subgraph
    Copy code
    <?xml version="1.0" encoding="utf-8"?>
    <navigation xmlns:android="<http://schemas.android.com/apk/res/android>"
        xmlns:app="<http://schemas.android.com/apk/res-auto>"
        android:id="@+id/main"
        app:startDestination="@id/graph1">
    
        <include app:graph="@navigation/graph1" />
        <include app:graph="@navigation/graph2" />
        <include app:graph="@navigation/graph3" />
    
        <include app:graph="@navigation/auth" />
    
        <action
            android:id="@+id/action_to_auth"
            app:destination="@id/auth"
            app:popUpTo="@id/graph1"
            app:popUpToInclusive="true"
            app:launchSingleTop="true" />
    
        <action
            android:id="@+id/action_to_main"
            app:destination="@id/graph1"
            app:popUpTo="@id/auth"
            app:popUpToInclusive="true"
            app:launchSingleTop="true" />
    </navigation>
    When starting the app if the user is logged out i redirect to auth flow using the `action_to_auth`and when he logs out, i’m calling
    navigate(R.id.action_to_auth)
    . The issue with multiple backstacks is that saved stacks aren’t cleared and there is no way to query what back stacks were previously saved into the fragment manager.
  • a

    Apex

    09/10/2021, 5:14 PM
    Does anyone have a good sample for handling User login/ register with Nav component? The docs recommend having a fixed start destination and applying authentication on pages that need it
  • a

    Apex

    09/10/2021, 5:15 PM
    But I don't want user to access any part of the app without authentication
    t
    • 2
    • 3
  • v

    Vivekpanchal64

    11/30/2021, 5:06 AM
    i have a login graph where once user logged in i navigate him to home screen. • but when he skip login and move to home screen and tries any user related action i want him to go back to login but once login i want him to stay at the page he was looking into. can anyone help me out how should i do this ?
  • c

    Cristina Uroz

    05/29/2022, 1:47 PM
    Hello everyone! A question relate to compose navigation: has anyone had trouble with navigation on a Xiaomi phone? I have a MIUI 13 that doesn’t complete the start navigation flow until you touch the screen
  • d

    Dhaval Gondaliya

    09/23/2022, 11:24 AM
    anyone know how to use
    findNavController()
    in
    Application
    class?
    • 1
    • 1
  • r

    Rafael Costa

    10/02/2022, 9:13 PM
    Hi all 👋 Could someone please explain to me how it is possible that ViewModels are not cleared on multi back stack scenario, since the corresponding NavBackStackEntries are popped from back stack, I really thought that would be the case, but I was surprised to find it isn't. I thought the state restoration would rely on the SavedStateHandle bundle to do it's thing, but seems like that's not the case, VMs are not even cleared.
  • w

    why

    04/12/2023, 1:54 PM
    Hello there. Is it possible to save the state of a nested navigation without popping up to start destination? I'm trying to implement a multi-stack navigation across bottomBar tabs. (navigation in Compose)
    Copy code
    navOptions {
                    popUpTo(navController.graph.findStartDestination().id) {
                        saveState = true
                    }
                    restoreState = true
                }
  • v

    Vivekpanchal64

    05/23/2023, 7:10 PM
    Hey Can someone guide me how to architect my base fragment to support to maintaining the view If user have came back from normal back press And if user done some action then comeback refresh the page and dont retain the view . Have anyone structured the same in baseFragment using databinding ??
  • g

    galex

    08/09/2023, 12:21 PM
    Hello, I've got Fragment A (Start Destination) and then Fragment B which both use the same ViewModel, both using
    saveStateHandle["id"]
    to get an id from a deeplink. When coming back from Fragment B to Fragment A, The ViewModel of Fragment A also receives the same parameter
    id
    as the ViewModel of Fragment B receives it. Weird or what am I missing here?
    d
    • 2
    • 2
  • n

    Nacho Ruiz Martin

    10/09/2023, 3:47 PM
    Hey 👋 After updating some libraries, when invoking
    onBackPressed
    on our Activities, navigation component’s
    popBackStack
    is not called, only
    finish
    , even if the graph is not on its root. Is this expected? Should we override the default back behaviour with
    OnBackPressedDispatcher
    to manually call
    popBackStack
    and
    finish
    when the backstack is cleared out?
  • y

    Yasutaka Kawamoto

    03/13/2024, 12:52 AM
    Hello, I'm using androidx.navigation:navigation-*:2.7.5 and noticed a potential issue with NavController#onGraphCreated not being called when calling setGraph twice. This seems to be related to the commit found here: https://android.googlesource.com/platform/frameworks/support/+/d22366d59a46aa16aa79d1d691cd5cb55f56c378 I'm trying to find a way to force NavController#onGraphCreated to be called in this scenario. Here's why I need this: I have an Activity with launchMode set to singleTop. • When the Activity is started for the first time, onCreate is called and NavController#setGraph is used to set the initial graph. • When the Activity is started again (via startActivity), onNewIntent is called. Inside onNewIntent, I call NavController#setGraph again to update the UI. This worked fine in 2.7.4, but in 2.7.5, the UI no longer updates when calling setGraph in onNewIntent. Is there any way to force NavController#onGraphCreated to be called in this situation? Any help would be greatly appreciated.
    d
    • 2
    • 2
  • a

    agrosner

    05/14/2024, 3:50 PM
    hey, for jetpack compose navigation, does anyone know when we dispatch multiple navigational events in a row, will the intermediate routes get rendered?:
    Copy code
    val navController = rememberNavController()
    navController.navigate(RouteA)
    navController.navigate(RouteB)
    will
    RouteA
    compose, or only compose when we go back from
    RouteB
    ?
    • 1
    • 1
  • n

    Natasha Jordanovska

    06/04/2024, 6:54 AM
    Hello everyone! I’m evaluating different strategies for implementing conditional navigation in a Jetpack Compose application and would love to hear your thoughts on the best practices. Here are three approaches I’m considering: 1. Centralized Navigation Logic with LaunchedEffect: This method involves managing a
    nextScreen
    state in the ViewModel, observed in the UI layer through a LaunchedEffect. Navigation commands are triggered in response to state changes, ensuring all navigation logic is centralized. 2. Callbacks in ViewModel: In this approach, navigation is triggered directly from ViewModel functions based on API call results or other conditions, using callbacks. This method avoids passing navigation logic to the UI and aligns with practices demonstrated in the JetSurvey app from the official Jetpack Compose samples, which can be found here. The Composables also define their own callbacks for navigation, ensuring a clean separation of concerns. 3. Using LiveData with Observers in Composables: Adapting a traditional approach where the ViewModel updates LiveData based on conditions, and Composables observe these changes to handle navigation. Although this is more common in architectures involving fragments, it could be adapted for Composables as detailed in the Android developer guide here. I’m particularly interested in scalability, testability, and ease of maintenance. Which approach do you prefer for conditional navigation in your projects, especially when using Composables, and why?
  • a

    Alvin Dizon

    07/08/2024, 11:54 PM
    Is Navigation 2.8.0 going to be released soon? I'm seeing crashes similar to https://issuetracker.google.com/issues/279644470 and it seems 2.8.0alpha01 and later versions has the fix, but would rather use a stable release if it's going to available soon.
    👀 1
    c
    • 2
    • 1
  • a

    agrosner

    08/05/2024, 4:28 PM
    hey using the
    AndroidFragment
    composable, it changes how fragments exist in the fragment manager of the host fragment. in this case, im hosting a
    NavHost
    within a fragment, where in the traditional version, same except using regular fragment transactions. When an
    AndroidFragment
    goes onto the backstack in navigation compose,
    onDispose
    is called, removing the fragment from the fragment manager. This changes how fragments typically exist in the pure fragment world, where they exist on the backstack with same instance. for legacy reasons, we have a bunch of screens expecting the same instance is used when fragment is reentered (setting fields improperly). In short, my guess is that this is expected behavior and that we should roll out our own variant of
    AndroidFragment
    emulating this behavior?
    • 1
    • 4
  • i

    Iman Sadrian

    09/11/2024, 12:56 PM
    Hello folks! I just posted my question here. It’s about finding a way to sync our DeepLinks in navgraph.xml with our DeepLink generator in Kotlin. I would appreciate any hints or if you could share your experience on this. Thanks! https://stackoverflow.com/questions/78973663/how-to-synchronize-deeplinks-between-navgraph-xml-and-my-kotlin-deeplink-generat
  • e

    Eduardo Ruesta

    09/11/2024, 3:35 PM
    Hey guys! i've been working on a Compose Multiplatform app. I used Voyager library for the navigation and everything works fine! but i wanted to move to navigation Compose. I did the migration, in Android works fine but on iOS all the lazyColumn and lazyRow for some reason feel rough when scrolling. Has anyone had something similar? I can't find what the problem could be. Thanks
  • d

    dave08

    09/15/2024, 11:15 AM
    Hi! Is there a way to make/use a generic CustomNavType that just serializes the content to Json using Kotlinx serialization and puts it in the bundle (I'm using the new type-safe navigation in 2.8.0...)?
    • 1
    • 1
  • d

    dave08

    09/15/2024, 11:17 AM
    Also, how to I test if I'm in a certain route with the type-safe nav api? I don't know the url of the route anymore... (unless I log it and hard code it's string 😵‍💫?)
  • a

    Andrey Nikanorov

    09/18/2024, 9:13 AM
    Hello, why NavController saves state only if it doesn't already exist? How it possible to replace the saved state, for example to update with the new deeplink params? https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:navigati[…]time/src/main/java/androidx/navigation/NavController.kt;l=739
  • a

    agrosner

    09/23/2024, 6:26 PM
    hey is there a good way not using restricted API to turn a typesafe Route into a full url string? Ive written up this function, but it is using internal APIs:
    Copy code
    /**
     * Generates a full route URL for a destination.
     *
     * This utilizes an internal jetpack compose typesafe navigation API.
     */
    @SuppressLint("RestrictedApi")
    fun Routable.fullRoute(destination: NavDestination): String {
        val args = destination.arguments.mapValues { it.value.type }
        val routeUrl = generateRouteWithArgs(this, args)
        return routeUrl
    }
    (Routable is our own restriction on route class instances) The use case is for tracking purposes id like to record its url value
  • v

    Vinicius Matheus

    09/24/2024, 2:15 PM
    Has anyone tried the
    navigation-fragment-compose
    ? I’m having an obfuscation problem. I tried to allow the generated class on the proguard, but I haven’t had any success yet. 😕
  • a

    agrosner

    11/22/2024, 3:50 PM
    anyone know why this is restricted, and not just public?
    Copy code
    // this restricted public is needed so that the public reified [popUpTo] can call
        // private popUpToRouteClass setter
        @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
        public fun <T : Any> popUpTo(klass: KClass<T>, popUpToBuilder: PopUpToBuilder.() -> Unit) {
    we have wrapper apis that we’d like to pass kclass vs recreating the route instance when popping current screen off the navigation stack. is there a better approach?
  • s

    stevie

    12/23/2024, 2:16 PM
    Hi, do we need anything else to set up Navigation typesafe? I am doing this:
    Copy code
    @Serializable
    data object HomeRoute // route to Main screen
    
    fun NavController.navigateToHome() = navigate(route = HomeRoute) {
        popUpTo(graph.id)
    }
    
    fun NavGraphBuilder.homeScreen() {
        composable<HomeRoute> {
            HomeScreen()
        }
    }
    But got this error when navigating back from another app:
    Copy code
    android.os.BadParcelableException: Parcelable encountered IOException writing serializable object (name = java.util.LinkedHashSet)
    ....
    Caused by: java.io.NotSerializableException: xxx.navigation.HomeRoute
  • t

    tylerwilson

    01/02/2025, 5:53 PM
    I am attempting to update from using XML based BottomNavigationView to a Compose NavigationView/NavHost, and I use XML navigation graphs extensively. Most of my current Fragments use findNavController().navigate etc. How do I construct a NavHost/NavController on the Compose side (I am trying NavigationSuiteScaffold) and then pass it down to the AndroidFragment wrapped Fragments? Thank you!
    a
    • 2
    • 3
  • j

    Joost Klitsie

    03/07/2025, 9:42 AM
    Hello people! 🙂 I am using Jetpack Compose and navigation component, I was wondering: can we pass a type safe argument to a nested navigation graph? In theory,
    navigation<MyGraph> {}
    supports the same type safe objects. I was hoping we can simply access the back stack entry for that and then read out the data we passed (more in the comment). Is this possible?
    ✅ 1
    • 1
    • 5
  • e

    enighma

    05/14/2025, 9:08 PM
    Is there a recommendation or best practice around using a Scaffold around the Navhost or instead vice versa and instead have one scaffold per screen? The former makes sense to me, but it makes it messy to communicate changes to let's say the top appbar. Do either of the example compose apps showcase this? I think the jetnews app uses a scaffold per screen.
  • t

    Tomáš Procházka

    05/19/2025, 11:54 PM
    I need to have custom compose
    NavHostController
    , I need to override
    handleDeepLink
    with custom implementation. Basically I need just provide a custom source of deep link intent, it is by default take from activity. I found no other way how to do it.
    NavHostController
    and even
    handleDeepLink
    is open so it should be easy to do it. But sadly it is not, because of
    rememberNavController()
    There is custom logic to create a instance of
    NavHostController
    which I need to reimplement too. There is this:
    Copy code
    private fun createNavController(context: Context) =
        NavHostController(context).apply {
            navigatorProvider.addNavigator(ComposeNavGraphNavigator(navigatorProvider))
            navigatorProvider.addNavigator(ComposeNavigator())
            navigatorProvider.addNavigator(DialogNavigator())
        }
    And sadly
    ComposeNavGraphNavigator
    is internal, so I can't create a own instance and use it. Nothing else is internal, just this one class. Why?