5

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.

Alex Alex
  • 131
  • 7

1 Answers1

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
  • 1
    Thanks, 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