Last active
August 29, 2015 14:23
-
-
Save andersonleite/8697f59fdcff8caf4fbc to your computer and use it in GitHub Desktop.
Parcelable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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