androidkotlinfragmentviewmodelandroid-safe-args

Safe-args: Passing an object from an imported package. Possible?


I'm trying to pass a Track object from the GPX Parser package that I've imported.

This is my navigation xml:

<argument
        android:name="track_to_pass"
        app:argType="io.ticofab.androidgpxparser.parser.domain.Track" />

I'm getting runtime exception:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mypackage.myapp/com.mypackage.myapp.MainActivity}: android.view.InflateException: Binary XML file line #10 in com.mypackage.myapp:layout/activity_main: Binary XML file line #10 in com.mypackage.myapp:layout/activity_main: Error inflating class androidx.fragment.app.FragmentContainerView

Can I pass it in any way to another fragment?


Solution

  • I'm getting runtime exception

    There should be much more to the stack trace than that.

    Safe-args: Passing an object from an imported package. Possible?

    As Ian notes in a comment, that will only be possible if the class implements Parcelable or Serializable. Presently, Track does not. You might file a feature request for Track and related types to be made Parcelable.