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:
Is it possible to get the current destination?
Java: Navigation.findNavController(v).getPreviousBackStackEntry().getDestination().getId();
Kotlin:
findNavController().previousBackStackEntry?.destination?.id
This should return you the previous destination's id in the 'X' fragment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With