5

What we try to achieve is when a user taps a notification, he/she should be redirected to a certain fragment. That destination fragment is marked as startDestination in the graph (it has its own .xml file).

To create the PendinIntent for this, we use the NavDeepLinkBuilder like this:

// `this` represents the notification service.
NavDeepLinkBuilder(this)
    .setGraph(R.navigation.destination_graph)
    .setDestination(R.id.start_destination)
    .createPendingIntent()

where R.id.start_destination is the id of the fragment specified in app:startDestination attribute of the root navigation tag in the R.navigation.destination_graph a.k.a. the start destination of that graph.

If we try to use this, we get the following error. If we use any other fragment other than the one marked as startDestination, it works seamlessly.

Our graph is this.

What could be the actual case and what's a workaround?

EDIT: If the graph is just like the above one, but it's missing its android:id attribute and it's not included in the BottomNavigationView, the error changes to Caused by: java.lang.IllegalStateException: unknown destination during deep link: 0 (line 3)

EDIT2: The above scenario, but the graph has an ID this time and is not used in any BottomNavigationView. The error becomes Caused by: java.lang.IllegalStateException: unknown destination during deep link: test.ourapp.app:id/messages

SnuKies
  • 1,578
  • 1
  • 16
  • 37
  • Does this answer your question? [Android Navigation Component: java.lang.IllegalStateException: unknown destination during restore](https://stackoverflow.com/questions/54496008/android-navigation-component-java-lang-illegalstateexception-unknown-destinati) which version are you using ? – Biscuit Feb 26 '20 at 14:49
  • No, my usecase is different – SnuKies Feb 26 '20 at 14:59
  • I just noticed that your destination `start_destination` has an `action`, in the code of your post there is no `setArgument`. Also, you could try to use `NavController.createDeepLink()` to create a `deepLink` then create your `pendingIntent`. – Biscuit Feb 28 '20 at 15:44

0 Answers0