i created a nav graph with fragments fragA->fragB->fragC-fragD->fragE->fragF->fragG. From some push notification user must directly go to fragG with findNavController().navigate(R.id.fragG)
, and when user tap back button he must go to fragF, but now is back to first fragment of navigation graph because fragB->fragC-fragD->fragE->fragF is not added to back stack. It's possible to add this frag to stack when user navigate to last an press back button? Thanks.
Asked
Active
Viewed 2,016 times
5

Alex Alex
- 131
- 7
-
https://developer.android.com/guide/navigation/navigation-deep-link – Raghunandan May 25 '20 at 07:24
-
in documentation wrote that only start destination is added to back stack, not all fragment till destination – Alex Alex May 25 '20 at 07:32
-
did you try it out – Raghunandan May 25 '20 at 10:00
-
Yes, is added only start destination – Alex Alex May 25 '20 at 11:02
1 Answers
3
It's not an official answer but it works as a workaround.
You can create the back stack manually by navigating sequentially.
fun openGFromPushNotification(){
navigate(R.id.fragB)
navigate(R.id.fragC)
navigate(R.id.fragD)
navigate(R.id.fragE)
navigate(R.id.fragF)
navigate(R.id.fragG)
}

beigirad
- 4,986
- 2
- 29
- 52
-
1Thanks, this really helped me. But it's depressing that this is the best option. You have to be careful to only use destination ids `R.id.fragB`, rather than action ids `R.id.fragA_to_fragB`, or safe args `FragADirections.actionFragAFragmentToFragBFragment()`. Only destination ids will work - the others will throw exceptions like `Navigation X cannot be found from the current destination`. – Luke Needham Feb 21 '22 at 17:55