Android Tutorial

(avery) #1
Android Tutorial 441

public final class GPXPoint implements Parcelable {
public int latitude;
public int longitude;
public Date timestamp;
public double elevation;
public static final Parcelable.Creator
CREATOR = new Parcelable.Creator() {
public GPXPoint createFromParcel(Parcel src) {
return new GPXPoint(src);
}
public GPXPoint[] newArray(int size) {
return new GPXPoint[size];


}
};
public GPXPoint() {
}
private GPXPoint(Parcel src) {
readFromParcel(src);
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(latitude);
dest.writeInt(longitude);
dest.writeDouble(elevation);
dest.writeLong(timestamp.getTime());
}
public void readFromParcel(Parcel src) {
latitude = src.readInt();
longitude = src.readInt();
elevation = src.readDouble();
timestamp = new Date(src.readLong());
}
public int describeContents() {
return 0;
}
}

The writeToParcel() method is required and flattens the object in a
particular order using supported primitive types within a Parcel.
When the class is created from a Parcel, the Creator is called,
Free download pdf