androidnavigationparcelabledeeplinkandroid-safe-args

Parcelables don't support default values. Android navigation deeplink argument


During the implementation of the passing parameter solution, in navigation between modules, I came across a serialization error. Deeplinks, as far as I know, accepts custom argument types, which are Parcelables or Serializable.

Im using newest version of navigation 2.2.0

Error message:

java.lang.UnsupportedOperationException: Parcelables don't support default values.

Am I doing something wrong or this is still under development?

Here is short example:

<fragment
    android:id="@+id/sampleFragment"
    android:name="com.testapp.app.samples.navigation.SampleFragment"
    android:label="SampleFragment">
    <argument
        android:name="Args"
        app:argType="com.testapp.navigation.SampleArgs" />
    <deepLink app:uri="app://app/samples/navigation/SampleFragment?Args={Args}"/>
</fragment>
@Parcelize
@Keep data class SampleArgs(
    val text: String
) : NavArgs, Parcelable
val x = SampleArgs("TEST")
val uri = Uri.parse("app://app/samples/navigation/SampleFragment?Args=$x")
navController.navigate(uri)

I found something similar here Android Parcelable don't support default values App Crash

It's my first post on stack, so please be gentle :)

EDIT

Here is answer:

https://issuetracker.google.com/issues/148523779


Solution

  • Parcelables currently don't support default values so you need to pass your object as String value. Yes it is a work around.. So instead of passing object itself as Parcelize object we can turn that object into JSON (String) and pass it through navigation and then parse that JSON back to Object at destination. You can use GSON for object to json-string conversion.