title: Making ArrayList of custom objects parcelable
body: <p>I have two classes which create Objects I need to pass through intents, I am currently attempting to implement Parcelable to do this.</p>
  
  <pre><code>import android.os.Parcel;
  import android.os.Parcelable;
  
  public class Item implements Parcelable {
  
      private String name;
      private double price;
      private int buyerCount = 0;
  
      public Item(String name, double price) {
          this.name = name;
          this.price = price;
      }
  
      private Item(Parcel in) {
          name = in.readString();
          price = in.readDouble();
      }
  
      public static final Parcelable.Creator&lt;Item&gt; CREATOR = new Parcelable.Creator&lt;Item&gt;() {
          public Item createFromParcel(Parcel in) {
              return new Item(in);
          }
  
          public Item[] newArray(int size) {
              return new Item[size];
          }
      };
  
      @Override
      public int describeContents() {
          return 0;
      }
  
      public double getPrice() {
          return price;
      }
  
      public int getBuyerCount() {
          return buyerCount;
      }
  
      public void incrementBuyerCount() {
          buyerCount += 1;
      }
  
      @Override
      public void writeToParcel(Parcel dest, int flags) {
          dest.writeString(name);
          dest.writeDouble(price);
      }
  }
  </code></pre>
  
  <p>From testing so far my Item object seems to transfer information correctly when I bundle it.</p>
  
  <p>However my second class Diner contains an ArrayList of objects Item and I'm unsure how to correctly implement Parcelable in this class, specifically in the parts where I have commented. I see there is a readParsableArray() method but nothing for ArrayLists.</p>
  
  <pre><code>import android.os.Parcel;
  import android.os.Parcelable;
  
  import java.util.ArrayList;
  
  public class Diner implements Parcelable {
  
      private String name;
      private ArrayList&lt;Item&gt; itemList = new ArrayList&lt;Item&gt;();
  
      public Diner(String name) {
          this.name = name;
      }
  
      private Diner(Parcel in) {
          name = in.readString();
          // How to read in ArrayList itemList of item objects?
          itemList = in.readParcelableArray();
      }
  
      public static final Parcelable.Creator&lt;Diner&gt; CREATOR = new Parcelable.Creator&lt;Diner&gt;() {
          public Diner createFromParcel(Parcel in) {
              return new Diner(in);
          }
  
          public Diner[] newArray(int size) {
              return new Diner[size];
          }
      };
  
      @Override
      public int describeContents() {
          return 0;
      }
  
      @Override
      public void writeToParcel(Parcel dest, int flags) {
          dest.writeString(name);
          // How to write ArrayList itemList of item objects?
          dest.writeParcelableArray(itemList);
      }
  
      public void addItem(Item foodItem) {
          itemList.add(foodItem);
          foodItem.incrementBuyerCount();
      }
  
      public double getPrice() {
          double total = 0;
          for(Item item : itemList) {
              total += item.getPrice() / item.getBuyerCount();
          }
          return total;
      }
  
      public String toString() {
          return name;
      }
  
  }
  </code></pre>