In my personal experience, http://www.parcelabler.com/ is a great site to do this. You simply create your class and copy, paste it into the website, and it generates a Parcelable version of your class.
I tested it with the "Theme" class, which contained the following variables:
private String name; private int image; private List<Card> cards;
The writeToParcel function becomes:
@Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(name); dest.writeInt(image); if (cards == null) { dest.writeByte((byte) (0x00)); } else { dest.writeByte((byte) (0x01)); dest.writeList(cards); } }
generated constructor:
protected Theme(Parcel in) { name = in.readString(); image = in.readInt(); if (in.readByte() == 0x01) { cards = new ArrayList<Card>(); in.readList(cards, Card.class.getClassLoader()); } else { cards = null; } }
EDIT: make sure the map object is also Parcelable!
Pieter Desseyn Jul 27 '18 at 11:51 2018-07-27 11:51
source share