Search code examples
androidandroid-architecture-navigationandroid-navigationandroid-jetpack-navigationandroid-deep-link

Using string constants in deeplink URI with Jetpack Navigation


Is it possible to use a string constant in the deep link URI?

Currently I have a few links, which lead to duplication of the host part:

<deepLink app:uri="www.host.com/a" />
<deepLink app:uri="www.host.com/b" />
<deepLink app:uri="www.host.com/c" />
<deepLink app:uri="www.host.com/d" />

I'm looking therefore for a way to extract somehow www.host.com.

I've been naively trying extracting it to strings.xml:

<string name="host">www.host.com</string>

and then:

<deepLink app:uri="{@string/host}/details/{id}" />

But this does not work (Improper use of wildcards and/or placeholders in deeplink URI host compilation error)


Solution

  • As mentioned in the comments to this question the OP wanted to use constant strings for multiple usage in the deep link uri's. The XML feature called Entity declaration allows to do that.

    A question with a similar goal was also answered here.