I have fragments A, B, C, and X where their navigations are as the following.
A --> X
B --> X
C --> X
How could I know the information of the last or previous destination in X?
The current destination ID can be found by
Navigation.findNavController(v).getCurrentDestination().getId()
I also tried using getBackStackEntry(int destinationId)
but it returns only the topmost NavBackStackEntry for a destination id. In other words, the current destination.
Also getActivity().getSupportFragmentManager().getBackStackEntryCount();
returning 0.
Possible solutions are:
- Pass data from A, B, and C to X and identify the previous fragment by checking with that data.
- Use shared SharedViewModel.
Is it possible to get the current destination?