'Android Safe Args crashing
So I'm trying to navigate to a Fragment with a deep link, and I keep crashing.
java.lang.UnsupportedOperationException: Parcelables don't support default values.
Here's the fragment in NavGraph
<fragment
android:id="@+id/appsAndDevicesFragment"
android:name="life.[REDACTED].wearable.wearablesettings.AppsAndDevicesFragment">
<argument
android:name="selectedDevice"
app:argType="string"
app:nullable="true" />
<argument
android:name="requiredDataPointsString"
app:argType="string"
android:defaultValue="@null"
app:nullable="true"/>
<argument
android:name="dataPoint"
android:defaultValue="@null"
app:argType="life.[REDACTED].wearable.model.WearableDataType"
app:nullable="true" />
<deepLink
android:id="@+id/deepLink9"
app:uri=".*/member/health/apps-and-devices?data_point={dataPoint}" />
<deepLink
android:id="@+id/deepLink11"
app:uri=".*/member/health/apps-and-devices?required_data_points_string={requiredDataPointsString}" />
Link code
(activity as? RootActivity)?.navigateToDeeplink(
url = WearableDeepLinker.WearablePaths.AppsAndDevices.construct(null),
openBrowserIfUnsupported = false,
setRootNavigation = false,
navController = findNavControllerSafely()
)
Here's the enum
@Parcelize
enum class WearableDataType(val value: String): Serializable, Parcelable {
@Json(name ="steps") STEPS("steps"),
@Json(name ="active_duration") ACTIVE_DURATION("active_duration"),
@Json(name ="mindful_duration") MINDFUL_DURATION("mindful_duration"),
@Json(name ="floors_climbed") FLOORS_CLIMBED("floors_climbed"),
@Json(name ="sleep_duration") SLEEP_DURATION("sleep_duration");
}
I'm not entirely sure what it means by default value, what default?
I've also tried wraping this in a data class but still get the same error
Solution 1:[1]
<argument
android:name="dataPoint"
android:defaultValue="@null"
app:argType="life.[REDACTED].wearable.model.WearableDataType"
app:nullable="true" />
Change it to string type.
<argument
android:name="dataPoint"
android:defaultValue="@null"
app:argType="string"
app:nullable="true" />
Also, if it is kotlin code. WearableDataType can't have null value as parameter.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alexander |
