In my app I have one Activity and the rest are fragments. Right now I am trying to get run as follows. Let's say, I have Fragments A (Home), B, and C. The scenario is this:
I navigate from A to B that shows me some data that I pass from A by Safe args. Then I navigate from B to C to edit data shown in B. Then I go back from C to B and B shows me the edited data in C. Lastly, I go back to home. That's all.
I pass data by Safe args, but the problem is, when I come back to B from C, I cannot navigate back to A because the navigateUp()
brings me back to C instead of going to A.
Navigating methods:
- From A to B:
Navigation.findNavController(requireActivity(), R.id.nav_host_fragment).navController().navigate(HomeFragmentDirections.actionNavHomeToNavB(some_string_data))
- From B to C:
Navigation.findNavController(requireActivity(), R.id.nav_host_fragment).navController().navigate(BFragmentDirections.actionNavBToNavC(string_data_in_B))
- From C to B:
Navigation.findNavController(requireActivity(), R.id.nav_host_fragment).navController().navigate(CFragmentDirections.actionNavCToNavB(edited_string_data_from_B))
- From B to A:
Navigation.findNavController(requireActivity(), R.id.nav_host_fragment).navController().navigateUp()
I also tried to use navigateUp()
before going back to B, which throws exception that the destination does not exist and also, I tried to use popBackStack()
to take the C from stack out so that the navigateUp()
in B can bring me back to Home. No success yet.