4

I want to pass Bitmapas an argument to another fragment using safe args. what is the correct argType for passing a bitmap.

<fragment
        android:id="@+id/nextFragment"
        android:name="com.example.----.NextFragment"
        android:label="fragment_next"
        tools:layout="@layout/fragment_next" >
        <argument
            android:name="image"
            app:argType="???"
            android:defaultValue="???" />
</fragment>
Askani
  • 424
  • 7
  • 19

1 Answers1

5

you can add argType as android.graphics.Bitmap

from the source code of NavType.java

Class clazz = Class.forName(className);
                if (Parcelable.class.isAssignableFrom(clazz)) {
                    return new ParcelableType(clazz);
                } else if (Enum.class.isAssignableFrom(clazz)) {
                    return new EnumType(clazz);
                } else if (Serializable.class.isAssignableFrom(clazz)) {
                    return new SerializableType(clazz);
                }

And Bitmap implements parcelable, so it will work.

You can remove the defaultValue

Rahul
  • 4,699
  • 5
  • 26
  • 38
  • thankz, but there is a problem, i want the bitmap to be null-able, and it is not allowing me to do it , Error: `Null can not be a value of a non-null type Bitmap`, how to fix it?.. am using kotlin – Askani Nov 01 '19 at 05:24
  • @Askani Adding `app:nullable="true"` to argument definition should help. – JerabekJakub Jul 08 '20 at 07:41