Navigate to a fragment from another graph without it being the start destination

后端 未结 1 1746
再見小時候
再見小時候 2020-12-16 07:03

In my first graph, I have the following:




        
相关标签:
1条回答
  • 2020-12-16 07:57

    As per the nested graph documentation:

    [Nested graphs] also provide a level of encapsulation — destinations outside of the nested graph do not have direct access to any of the destinations within the nested graph.

    There is one exception to that, when you are navigating using a URI, effectively deep linking into any destination:

    Unlike navigation using action or destination IDs, you can navigate to any URI in your graph, regardless of whether the destination is visible. You can navigate to a destination on the current graph or a destination on a completely different graph.

    Therefore you can add an implicit deep link to your graph:

    <fragment
        android:id="@+id/detailsFragment"
        android:name="com.example.DetailsFragment">
        <deepLink app:uri="android-app://your.package.name/details" />
    </fragment>
    

    Then navigate to that destination via URI:

    val uri = Uri.parse("android-app://your.package.name/details")
    navController.navigate(uri)
    

    It doesn't matter what your URI is, as long as the <deepLink> and what you pass to navigate match. Any arguments you have would need to be encoded in the URL.

    0 讨论(0)
提交回复
热议问题