Search code examples
androidandroid-architecture-navigationandroid-navigation-graph

Handling Array Query Params Using Navigation Component Deep Linking


I am using a single activity structure in my project, and I want to handle deep (app) linking using the navigation component. All thing is good, but I can't handle array query params. I want to get complex_types as an array of String.

Existing URL:

my.example.com/?guests=1&complex_types=hotel&complex_types=motel

nav_graph.xml:

     <fragment
        android:id="@+id/complexFragment"
        android:name="com.the.example.packagename.ComplexFragment"
        android:label="ComplexFragment">
        <argument
            android:name="guests"
            android:defaultValue="1"
            app:argType="integer" />
        <argument
            android:name="complexFilters"
            app:argType="???" />
        <deepLink
            android:id="@+id/deepLink_complex_fragment"
            app:uri="my.example.com/?guests={guests}&amp;complex_types={complexFilters}" />
    </fragment>

I don't know what type of argType must be used instead of ??? in complexFilters argument.


Solution

  • In the android editor there is a checkbox for array or you enter image description here

    and in the xml navigation graph will be like this

       <argument
            android:name="images"
            android:defaultValue="@null"
            app:argType="string[]"
            app:nullable="true" />