Vyshas
08/02/2021, 8:57 PMbinding.bottomNavigationView.setupWithNavController(navController)
If I use below, then bottom nav selection stops working.
binding.bottomNavigationView.setOnItemSelectedListener {
//track clicks
true
}
Tepes Lucian Victor
09/03/2021, 4:11 PM<?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.Apex
09/10/2021, 5:14 PMApex
09/10/2021, 5:15 PMVivekpanchal64
11/30/2021, 5:06 AMCristina Uroz
05/29/2022, 1:47 PMDhaval Gondaliya
09/23/2022, 11:24 AMfindNavController()
in Application
class?Rafael Costa
10/02/2022, 9:13 PMwhy
04/12/2023, 1:54 PMnavOptions {
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
restoreState = true
}
Vivekpanchal64
05/23/2023, 7:10 PMgalex
08/09/2023, 12:21 PMsaveStateHandle["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?Nacho Ruiz Martin
10/09/2023, 3:47 PMonBackPressed
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?Yasutaka Kawamoto
03/13/2024, 12:52 AMagrosner
05/14/2024, 3:50 PMval navController = rememberNavController()
navController.navigate(RouteA)
navController.navigate(RouteB)
will RouteA
compose, or only compose when we go back from RouteB
?Natasha Jordanovska
06/04/2024, 6:54 AMnextScreen
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?Alvin Dizon
07/08/2024, 11:54 PMagrosner
08/05/2024, 4:28 PMAndroidFragment
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?Iman Sadrian
09/11/2024, 12:56 PMEduardo Ruesta
09/11/2024, 3:35 PMdave08
09/15/2024, 11:15 AMdave08
09/15/2024, 11:17 AMAndrey Nikanorov
09/18/2024, 9:13 AMagrosner
09/23/2024, 6:26 PM/**
* 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 valueVinicius Matheus
09/24/2024, 2:15 PMnavigation-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. 😕agrosner
11/22/2024, 3:50 PM// 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?stevie
12/23/2024, 2:16 PM@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:
android.os.BadParcelableException: Parcelable encountered IOException writing serializable object (name = java.util.LinkedHashSet)
....
Caused by: java.io.NotSerializableException: xxx.navigation.HomeRoute
tylerwilson
01/02/2025, 5:53 PMJoost Klitsie
03/07/2025, 9:42 AMnavigation<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?enighma
05/14/2025, 9:08 PMTomáš Procházka
05/19/2025, 11:54 PMNavHostController
, 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:
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?