NavGraph深度链接



我有这个使用BottomNavigationView的导航图,其中有两个片段,Home和Search,都转到Detail fragment

MainGraph.xml

<?xml version="1.0" encoding="utf-8"?>
<navigation
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_graph"
app:startDestination="@+id/home">
<include app:graph="@navigation/home"/>
<include app:graph="@navigation/search"/>
</navigation>

主页图

<navigation
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/home"
app:startDestination="@+id/homeScreen">
<fragment
android:id="@+id/homeScreen">
<action
android:id="@+id/action_home_to_detail"
app:destination="@id/detailScreen" />

<include app:graph="@navigation/detail"/>
</navigation>

搜索图

<navigation
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/search"
app:startDestination="@+id/searchScreen">
<fragment
android:id="@+id/searchScreen">
<action
android:id="@+id/action_search_to_detail"
app:destination="@id/detailScreen" />

<include app:graph="@navigation/detail"/>
</navigation>

DetailGraph

<navigation
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/detail"
app:startDestination="@id/detailScreen">
<argument
android:name="detailID"
android:defaultValue='""'
app:argType="string" />
<fragment
android:id="@+id/detailScreen"
tools:layout="@layout/fragment_detail">

<argument
android:name="detailID"
android:defaultValue='""'
app:argType="string" />

<deepLink
android:id="@+id/deepLinkDetail"
app:uri="domain.com/detail?id={detailID}" />
</fragment>
</navigation>

当我点击url时,detailScreen打开得很好,但findNavController().previousBackStackEntrynull

目前,如果previousBackStackEntry为空,我会重新启动应用程序

requireActivity().finish()
requireActivity().startActivity(Intent(requireContext(), MainActivity::class.java))
requireActivity().finishAffinity()

非常感谢

已解决

我在清单中的SplashActivity声明中使用了意向过滤器,而不是MainActivity

相关内容

  • 没有找到相关文章

最新更新