kivaari icon

parcelable example

kivaari | PRO | 01/24/17 01:04:11 PM UTC | 0 ⭐ | 300 👁️ | Never ⏰ | []
Java |

1.08 KB

|

None

|

0 👍

/

0 👎

    private Car(Parcel in){
        door = new Integer[MAX_DOORS];
 
        for(int i = 0; i < MAX_DOORS; i++)
            door[i] = in.readInt();
 
        tank = in.readInt();
        temp = in.readDouble();
 
        try {
            start = new JSONObject(in.readString());
            route = new JSONArray(in.readString());
            history = new JSONArray((in.readString()));
        } catch (JSONException e) {e.printStackTrace();}
    }
 
@Override
    public void writeToParcel(Parcel dest, int flags) {
        for(int i = 0; i < MAX_DOORS; i++)
            dest.writeInt(door[i]);
 
        dest.writeInt(tank);
        dest.writeDouble(temp);
 
        dest.writeString(start.toString());
        dest.writeString(route.toString());
        dest.writeString(history.toString());
    }
 
    public static final Parcelable.Creator<Car> CREATOR = new Parcelable.Creator<Car>() {
        public Car createFromParcel(Parcel in) {
            return new Car(in);
        }
 
        public Car[] newArray(int size) {
            return new Car[size];
        }
    };

Comments