How to call another navgraph fragment from another nav graph without lossing current destination in andorid

461 Views Asked by At

I have Two navgraph inside my project

  • graphA { I have some fragments inside my ( Graph A ) login fragment ( this fragment set as home ) and signup fragment }
  • graphB { I have some fragments inside my ( Graph B )
  • home ( this fragment set as home )
  • profile }

Scenario { once user get logged In successfully I want to navigate user to -> graphB(Profile Page) but once user press back button he go back to Graph B (Home Fragment) }

1

There are 1 best solutions below

0
On

In logged successfully response you redirect your fragment to profile page

            findNavController(R.id.nav_host_fragment).navigate(R.id.navigation_profile_page)

and on back button redirect the home fragment

            findNavController(R.id.nav_host_fragment).navigate(R.id.navigation_home)