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

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) }



Solution 1:[1]

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)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yash Shah