deanWombourne
deanWombourne

Reputation: 38475

Navigation graph won't use default arguments in deeplink

I have a fragment in a navigation graph with two parameters (ids: List<Int>? and name: String?) - these both have default values set (both set to @null).

I have created a deeplink to this fragment from the pattern mysite.com/{name} but after upgrading to navigation version 2.4.0-alpha08 I get this error when running my app:

Caused by: java.lang.IllegalArgumentException: Deep link mysite.com/{name} can't be used to open destination Destination(com.mysite:id/myFragment) class=com.mysite.MyFragment.
    Following required arguments are missing: [ids]

As the exception is thrown when inflating my MainActivity.xml, it seems like the default value for ids is being ignored when validating the deeplink.

This didn't happen in version 2.4.0-alpha06.

Is this a bug in this version of the navigation component (I'll raise a bug if so), or is this just better validation in that component revealing a bug in my code - if so, what's the fix?

Upvotes: 3

Views: 1396

Answers (2)

Filipe Bezerra de Sousa
Filipe Bezerra de Sousa

Reputation: 3032

Jetpack Navigation version 2.5.0-alpha04 release note mentions a fix to solve this kind of problem:

enter image description here

Upvotes: 0

deanWombourne
deanWombourne

Reputation: 38475

Horribly, here's the hack I'm using.

URL parameters are optional if their value has a default set, so my deeplinks in the navigation graph now look like this:

mysite.com/{name}?this_wont_ever_really_happen={ids}

which matches the url mysite.com/{name} because ids has a default value (of @null)

Upvotes: 3

Related Questions