Skip to content

Instantly share code, notes, and snippets.

@andersonleite
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andersonleite/8697f59fdcff8caf4fbc to your computer and use it in GitHub Desktop.
Save andersonleite/8697f59fdcff8caf4fbc to your computer and use it in GitHub Desktop.
Parcelable
public class House implements Parcelable {
private Integer rooms;
private String color;
protected House(Parcel in) {
rooms = in.readByte() == 0x00 ? null : in.readInt();
color = in.readString();
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
if (rooms == null) {
dest.writeByte((byte) (0x00));
} else {
dest.writeByte((byte) (0x01));
dest.writeInt(rooms);
}
dest.writeString(color);
}
@SuppressWarnings("unused")
public static final Parcelable.Creator<House> CREATOR = new Parcelable.Creator<House>() {
@Override
public House createFromParcel(Parcel in) {
return new House(in);
}
@Override
public House[] newArray(int size) {
return new House[size];
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment