There is such a method in the activity that responsible to open the fragments by Uri
...
fun navigate(uri: Uri, savedInstanceState: Bundle?) {
with(supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment) {
val authGraph: NavGraph = navController.navInflater.inflate(R.navigation.auth_nav_graph)
maybeSetIapNavGraphs(navHostFragment.navController, authGraph)
navController.graph = authGraph
if (savedInstanceState == null) {
navController.popBackStack()
navController.navigate(uri)
}
}
}
...
I need to pass a boolean value to the fragment that is going to be opened, however, I see that navigate
doesn't take Bundle
as a param, and the only available constructor with Uri
is .navigate(uri, NavOptions)
, so looks like there is no way to pass a bundle.
The question is - how to pass a boolean value to the fragment?
UPD
I also tried to do it like this:
...
fun navigate(uri: Uri, savedInstanceState: Bundle?) {
with(supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment) {
val authGraph: NavGraph = navController.navInflater.inflate(R.navigation.auth_nav_graph)
maybeSetIapNavGraphs(navHostFragment.navController, authGraph)
val bundle = Bundle().apply { putInt("isEnabled", 1) }
navController.setGraph(authGraph, bundle)
if (savedInstanceState == null) {
navController.popBackStack()
navController.navigate(uri)
}
}
}
...
However, when I try to get this value in the fragment like
val arg1Value = requireArguments().getInt("isEnabled")
it gives 0