gpt4 book ai didi

android - NavDeepLinkBuilder 没有重定向到目标 fragment

转载 作者:行者123 更新时间:2023-12-05 00:04:28 25 4
gpt4 key购买 nike

我在多个 Activity 中使用多个导航图,并尝试深层链接到特定的导航图目标 fragment ,但它正在打开启动器 Activity

 val args = Bundle()
args.putParcelable("parceable",parceableObject)
args.putString("type","type")

val pendingIntent = NavDeepLinkBuilder(applicationContext)
.setGraph(R.navigation.bottom_nav_navigation)
.setDestination(R.id.myFragment)
.setArguments(args)
.createPendingIntent()

这就是我创建 NavDeepLinkBuilder 的方式。

下图是导航图中的目的地

<fragment
android:id="@+id/myFragment"
android:name="com.view.brands.MyFragment"
android:label="BrandOffersFragment"
>

<argument
android:name="parceableObject"
app:argType="com.view.brands.ParceableObject"
/>
<argument
android:name="type"
app:argType="string"
/>
<argument
android:name="is_card"
android:defaultValue="false"
app:argType="boolean"/>
<action
android:id="@+id/action_myFragment_to_secondFragment"
app:destination="@id/secondFragment"
>
<argument android:name="secondParceable"
app:argType="com.view.brands.SecondParceable"/>
<argument
android:name="parceableObject"
app:argType="com.view.brands.ParceableObject"
/>
<argument
android:name="type"
app:argType="string"
/>
</action>
<action
android:id="@+id/action__myFragment_to_thirdFragment"
app:destination="@id/ThirdFragment"
>
<argument
android:name="thirdParceable"
app:argType="com.view.network.parceable.ThirdParceable"
/>
</action>
<action
android:id="@+id/action_myFragment_to_thirdActivity"
app:destination="@id/ThirdActivity"
>
<argument
android:name="card"
app:argType="com.network.apiinterface.Card"
/>
<argument
android:name="id"
app:argType="string"
/>
</action>
</fragment>

最佳答案

您没有为 com.view.brands.MyFragment 使用正确的参数

<fragment
android:id="@+id/myFragment"
android:name="com.view.brands.MyFragment"
android:label="BrandOffersFragment">

<argument
android:name="parceableObject" // issue start from here
app:argType="com.view.brands.ParceableObject"/>
<argument
android:name="type"
app:argType="string"/>
<argument
android:name="is_card"
android:defaultValue="false"
app:argType="boolean"/>
</fragment>

您在为 MyFragment 创建 arg 时传递的内容。

val args = Bundle()
args.putParcelable("parceable",parceableObject) //must be "parceableObject"
.....

我会建议你使用 safeArg以避免将来出现此类错误。

编码愉快!

关于android - NavDeepLinkBuilder 没有重定向到目标 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63267659/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com