NavDeepLinkBuilder is not redirecting to the destination fragment

Viewed 1261

I am using multiple navigation graph with multiple activities, and trying to deep link to a specific navigation graph destination fragment but it is opening the launcher 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()

This is how I am creating NavDeepLinkBuilder.

Following is the destination in the navigation graph look like

<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>
1 Answers

You are not using correct argument for 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>

What you are passing while creating arg for MyFragment.

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

I will suggest you to use safeArg to avoid these kind of mistake in future.

happy coding !

Related