10

How can I return to the root Fragment using the NavController? I tried

navController.popBackStack(navController.graph.startDestination, false)

but it did not work. This did work:

navController.navigate(navController.graph.startDestination, false)
navController.popBackStack(0, false)

but I'm wondering if this is a proper way to solve this problem.

artkoenig
  • 7,117
  • 2
  • 40
  • 61

1 Answers1

16

you can use this method, but your arguments are wrong, The first argument is the ID of destination, for back to root you have to use:

findNavController().popBackStack(R.id.Dashboard, false)

Where Dash is the ID of view on your navigation graph

Lucas Paim
  • 417
  • 4
  • 13