0

I have 2 nav host activities Activity A and Activity B with each their own set of navigation graphs. I want to navigate from FragmentA which is in a nav graph hosted by Activity A to FragmentB which is in a nav graph hosted by Activity B to accomplish that i tried explicit deep linking. However no matter how I am not able to retrieve the argument in FragmentB its always the default value. I am using safe args. What am I doing wrong?

update: it seems the problem starts with a not accessible nav graph. Looking a bit more closely at the Log i realized that NavController logged the following message

Could not find destination com.myapp.app:id/nav_graph_b in the navigation graph, ignoring the deep link from Intent....

the nav graph is hosted by the nav host activity B which is set in setComponentName. Why is the graph not accessible then?

the deeplink

val bundle = Bundle()
bundle.putInt("theIntKey", theInt)

val pendingIntent = NavDeepLinkBuilder(requireContext())
    .setComponentName(NavHostActivityB::class.java)
    .setGraph(R.navigation.nav_graph_b)
    .setDestination(R.id.fragmentB)
    .setArguments(bundle)
    .createPendingIntent()
    .send()

navgraph

  <navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/nav_graph_b"
    app:startDestination="@id/fragmentC"
    tools:ignore="UnusedNavigation">
    
        <fragment
            android:id="@+id/fragmentB"
            android:name="FragmentB">
            <argument
                android:name="theIntKey"
                app:argType="integer"
                android:defaultValue="0" />
        </fragment>
        
           <!--  other fragments-->
           
    </navigation>

inside FragmentB

//all of these three methods return always the default value
val theIntFromBundle = requireArguments().getInt("theIntKey")

private val args: FragmentBArgs by navArgs()

requireActivity().intent.extras?.let {
    val args = FragmentBArgs.fromBundle(it)
}
Macs
  • 197
  • 2
  • 15
  • by by adding the intent with extras to the send method i was able to receive the arguments from the hosting activity like so requireActivity().intent.extras?.let { val args = FragmentBArgs.fromBundle(it) }. the fragment obviously does not receive anything!? – Macs Jul 11 '20 at 06:53
  • by the way i realized that this kind of deeplinking only works if FragmentB is the start destination of the graph. if as shown in my example the start destination is some other fragment it will navigate to that fragment. hence the set destination seems not to do anything? Is that intended behavior?? – Macs Jul 11 '20 at 08:28
  • i just realized that i got an debug log from navcontroller saying Could not find destination com.myapp.app:id/nav_graph_b in the navigation graph, ignoring the deep link from Intent. It seems this explains my troubles in a way but does not solve my problem. I updated my question – Macs Jul 11 '20 at 12:25
  • did you solve your issue? could you post solution? – LunaVulpo Dec 08 '20 at 15:28
  • no unfortunately i did not – Macs May 11 '22 at 05:23

0 Answers0