Advertisement
kivaari

parcelable example

Jan 24th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1.     private Car(Parcel in){
  2.         door = new Integer[MAX_DOORS];
  3.  
  4.         for(int i = 0; i < MAX_DOORS; i++)
  5.             door[i] = in.readInt();
  6.  
  7.         tank = in.readInt();
  8.         temp = in.readDouble();
  9.  
  10.         try {
  11.             start = new JSONObject(in.readString());
  12.             route = new JSONArray(in.readString());
  13.             history = new JSONArray((in.readString()));
  14.         } catch (JSONException e) {e.printStackTrace();}
  15.     }
  16.  
  17. @Override
  18.     public void writeToParcel(Parcel dest, int flags) {
  19.         for(int i = 0; i < MAX_DOORS; i++)
  20.             dest.writeInt(door[i]);
  21.  
  22.         dest.writeInt(tank);
  23.         dest.writeDouble(temp);
  24.  
  25.         dest.writeString(start.toString());
  26.         dest.writeString(route.toString());
  27.         dest.writeString(history.toString());
  28.     }
  29.  
  30.     public static final Parcelable.Creator<Car> CREATOR = new Parcelable.Creator<Car>() {
  31.         public Car createFromParcel(Parcel in) {
  32.             return new Car(in);
  33.         }
  34.  
  35.         public Car[] newArray(int size) {
  36.             return new Car[size];
  37.         }
  38.     };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement