Search code examples
androidparcel

How to add a Drawable object to a Parcel object in android?


I'm facing problem in adding a drawable object to a Parcel object, in order to send an object from one activity to another activity.

There are methods like writeString(String) to add strings to a Parcel object. But do not know how to add a Drawable to the Parcel object.


Solution

  • You cannot add a Drawable to a Parcel, as Drawable does not implement the Parcelable interface. Certain types of Drawable might implement Parcelable, but I am not aware of any.

    You can put in the Parcel some identifier (e.g., drawable resource ID) and have the recipient obtain the Drawable on its own.