Code example for Parcel

Methods: readArrayList, readInt, readString

0
	} 
	 
	 
	@SuppressWarnings("unchecked") 
	private void readFromParcel(Parcel in) {
		route_id = in.readString();
		title = in.readString();
		interval = in.readInt();
		isSafeRide = readBool(in);
		isRunning = readBool(in);
		gpsActive = readBool(in);
		vehicleLocations = in.readArrayList(RouteItem.class.getClassLoader());
		summary = in.readString();
		stops = in.readArrayList(Stops.class.getClassLoader());
	} 
	 
	public static final Parcelable.Creator<RouteItem> CREATOR = new Parcelable.Creator<RouteItem>() {
 
		@Override 
		public RouteItem createFromParcel(Parcel source) { 
			RouteItem routeItem = new RouteItem(); 
			routeItem.readFromParcel(source); 
			return routeItem; 
		} 
 
		@Override 
		public RouteItem[] newArray(int size) { 
			return new RouteItem[size]; 
		} 
	}; 
	 
	 
	public static class Loc implements Parcelable {
		public float lat;
		public float lon;
		 
		public static final Parcelable.Creator<Loc> CREATOR = new Parcelable.Creator<Loc>() {
 
			@Override 
			public Loc createFromParcel(Parcel source) { 
				Loc loc = new Loc(); 
				loc.lat = source.readFloat(); 
				loc.lon = source.readFloat(); 
				return loc; 
			} 
 
			@Override 
			public Loc[] newArray(int size) { 
				return new Loc[size]; 
			}			 
		}; 
	 
 
		@Override 
		public int describeContents() { 
			return 0; 
		} 
 
		@Override 
		public void writeToParcel(Parcel dest, int flags) {
			dest.writeFloat(lat);
			dest.writeFloat(lon);
		} 
	} 
	 
	public static class Stops implements Parcelable {
		 
		public Stops () { 
			path = new ArrayList<Loc>();
			predictions = new ArrayList<Integer>();
		} 
		 
		public Stops(Parcel in) {
			readFromParcel(in);
		} 
		 
		public boolean alertSet = false;
		 
		public String route_id;  // needed if not enclosed by RouteItem
		public String id;
		public String title;
		public String lat;
		public String lon;
		public long next;  // next arrival unixtime
		public long now; // reference time for predictions
		public ArrayList<Integer> predictions;
		public String direction;
		public ArrayList<Loc> path;
 
		public boolean upcoming = false;
		public boolean gps;
		 
		public static final Parcelable.Creator<Stops> CREATOR = new Parcelable.Creator<Stops>() {
 
			@Override 
			public Stops createFromParcel(Parcel source) { 
				return new Stops(source); 
			} 
 
			@Override 
			public Stops[] newArray(int size) { 
				return new Stops[size]; 
			} 
			 
		}; 
		 
		@Override 
		public void writeToParcel(Parcel out, int flags) {
			out.writeString(route_id);
			out.writeString(id);
			out.writeString(title);
			out.writeString(lat);
			out.writeString(lon);
			out.writeLong(next);
			out.writeList(predictions);
			out.writeString(direction);
			out.writeList(path);
			writeBool(out, upcoming);
			writeBool(out, gps);
		} 
		 
		@SuppressWarnings("unchecked") 
		public void readFromParcel(Parcel in) {
			route_id = in.readString();
			id = in.readString();
			title = in.readString();
			lat = in.readString();
			lon = in.readString();
			next = in.readLong();
			 
			predictions = (ArrayList<Integer>) in.readArrayList(Integer.class.getClassLoader());
			 
			direction = in.readString();
						 
			path = in.readArrayList(Loc.class.getClassLoader());
			 
			upcoming = readBool(in);
			gps = readBool(in);
		} 
 
		@Override 
		public int describeContents() { 
			return 0; 
		} 
	} 
	 
	/**************************/ 
	void parseListView() { 
		 
	} 
	void parseDetails() { 
		 
	} 
	 
	private static void writeBool(Parcel dest, boolean bool) {
		dest.writeInt(bool ? 1 : 0);
	} 
	 
	private static boolean readBool(Parcel in) {
		return (in.readInt() == 1);
	} 
} 
 
/* 
[