How to pass object of type Parcelable to a Fragment using Navigation type safeargs plugin

Jerry Okafor picture Jerry Okafor · Jun 3, 2018 · Viewed 16.6k times · Source

I am rewriting my simple UI app to use Navigation architecture component, I need to pass a Pojo that implements Parcelable, have not seen any doc on how to do that.

Any help would be appreciated.

Answer

mbo picture mbo · Oct 1, 2018

Since safe-args-gradle-plugin:1.0.0-alpha03 you can use Parcelable objects by using their fully qualified class name:

<argument
    android:name="item"
    app:argType="com.example.app.model.Item"/>

Parcelable arguments are now supported, using a fully qualified class name for app:type. The only default value supported is "@null" (https://issuetracker.google.com/issues/79563966)

Source: https://developer.android.com/jetpack/docs/release-notes


To support nullability one has to use android:defaultValue="@null" with app:nullable="true".