title: Pass custom object between activities
body: <p>I've tried many different solutions found here and many other sites - but i just can't make it work!</p>
  
  <p>I have an object "Apartment" in one activity which is to be used in another activity.
  The activity is started from the class MyMapOverlayItem and should start the ApartmentInfoActivity in which the Apartment object should be used.</p>
  
  <p>MyMapOverlayItem.java :</p>
  
  <pre><code>package com.android.madsoft.spotter;
  
  import java.util.ArrayList;
  
  import android.content.Context;
  import android.content.Intent;
  import android.graphics.drawable.Drawable;
  import android.os.Bundle;
  
  import com.google.android.maps.ItemizedOverlay;
  import com.google.android.maps.OverlayItem;
  
  public class MyMapOverlayIcon extends ItemizedOverlay&lt;OverlayItem&gt; {
      Context mContext;
      ArrayList&lt;Apartment&gt; myList;
      private ArrayList&lt;OverlayItem&gt; mOverlays = new ArrayList&lt;OverlayItem&gt;();
      public MyMapOverlayIcon(Drawable defaultMarker) {
          super(defaultMarker);
  
      }
  
      public MyMapOverlayIcon(Drawable defaultMarker, Context context, ArrayList&lt;Apartment&gt; myList) {
          super(boundCenterBottom(defaultMarker));
            mContext = context;
            this.myList = myList;
  
          }
  
      public void addOverlay(OverlayItem overlay) {
          mOverlays.add(overlay);
          populate();
      }
  
      @Override
      protected boolean onTap(int index) {
          Apartment ap = myList.get(index);
          ApartmentParcel ap1 = new ApartmentParcel(ap);
          Intent i = new Intent(mContext, ApartmentInfoActivity.class);
          Bundle b = new Bundle();
          b.putParcelable("app", ap1);
          i.putExtras(b);
  //      i.putExtra("app",ap1);
  //      b.putSerializable("apartment", ap);
  
          // WHAT TO DO!?
  
          mContext.startActivity(i);
  
        return true;
      }
  
      @Override
      protected OverlayItem createItem(int i) {
        return mOverlays.get(i);
      }
  
      @Override
      public int size() {
        return mOverlays.size();
      }
  
  }
  </code></pre>
  
  <p>Apartment.java :</p>
  
  <pre><code>package com.android.madsoft.spotter;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.net.HttpURLConnection;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.util.ArrayList;
  
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  
  
  public class Apartment {
  
  
      private static final long serialVersionUID = 1L;
      int latitude, longitude;
      String id, 
      zipcode, 
      size, 
      rooms, 
      rentprice, 
      deposit, 
      takeoverdate, 
      rentperiod, 
      furniturized, 
      usagecost, 
      addeddate, 
      description,
      prepaid;
      ArrayList&lt;String&gt; imageList, phonenumbers;
      int imagecount = 1;
      ArrayList&lt;Bitmap&gt; bigBitmapList;
      ArrayList&lt;Bitmap&gt; smallBitmapList;
  
      public Apartment(String id, int latitude, int longitude, 
                      String zipcode, String size, String rooms, 
                      String rentprice, String deposit, String prepaid, String takeoverdate, 
                      String rentperiod, String furniturized, String usagecost, 
                      String addeddate, String description, ArrayList&lt;String&gt; imageList, ArrayList&lt;String&gt; phonenumbers){
          bigBitmapList = new ArrayList&lt;Bitmap&gt;();
          smallBitmapList = new ArrayList&lt;Bitmap&gt;();
          this.addeddate = addeddate;
          this.deposit = deposit;
          this.description = description;
          this.furniturized = furniturized;
          this.id = id;
          this.imageList = imageList;
          this.latitude = latitude;
          this.longitude = longitude;
          this.phonenumbers = phonenumbers;
          this.prepaid = prepaid;
          this.rentperiod = rentperiod;
          this.rentprice = rentprice;
          this.rooms = rooms;
          this.size = size;
          this.takeoverdate = takeoverdate;
          this.usagecost = usagecost;
          this.zipcode = zipcode;
  
          for (String s :imageList){
  
              URL myFileUrl = null;
              try {
                   myFileUrl= new URL(s);
              } catch (MalformedURLException e) {
                   e.printStackTrace();
              }
              try {
                   HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
                   conn.setDoInput(true);
                   conn.connect();
                   InputStream is = conn.getInputStream();
                   Bitmap image = BitmapFactory.decodeStream(is); //Saves the current icon
                   bigBitmapList.add(image);
                   //Icon will now be resized to 125px*100px               
                      Bitmap resized; 
                      int scalerate = (int)image.getHeight()/60;
                      int newHeight = (int)image.getHeight()/scalerate;
                      int newWidth = (int)image.getWidth()/scalerate; 
                      resized = Bitmap.createScaledBitmap(image, newWidth, newHeight, false);
                      smallBitmapList.add(resized);
              }
              catch (IOException e) {
                  e.printStackTrace();
              }
              }
          }
  </code></pre>
  
  <p>ApartmentParcel.java :</p>
  
  <pre><code>package com.android.madsoft.spotter;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.net.HttpURLConnection;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.util.ArrayList;
  
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.os.Parcel;
  import android.os.Parcelable;
  
  public class ApartmentParcel implements Parcelable {
  
      private static final long serialVersionUID = 1L;
      int latitude, longitude;
      String id, 
      zipcode, 
      size, 
      rooms, 
      rentprice, 
      deposit, 
      takeoverdate, 
      rentperiod, 
      furniturized, 
      usagecost, 
      addeddate, 
      description,
      prepaid;
      ArrayList&lt;String&gt; imageList, phonenumbers;
      int imagecount = 1;
      ArrayList&lt;Bitmap&gt; bigBitmapList;
      ArrayList&lt;Bitmap&gt; smallBitmapList;
  
      public ApartmentParcel(String id, int latitude, int longitude, 
                      String zipcode, String size, String rooms, 
                      String rentprice, String deposit, String prepaid, String takeoverdate, 
                      String rentperiod, String furniturized, String usagecost, 
                      String addeddate, String description, ArrayList&lt;String&gt; imageList, ArrayList&lt;String&gt; phonenumbers){
          bigBitmapList = new ArrayList&lt;Bitmap&gt;();
          smallBitmapList = new ArrayList&lt;Bitmap&gt;();
          this.addeddate = addeddate;
          this.deposit = deposit;
          this.description = description;
          this.furniturized = furniturized;
          this.id = id;
          this.imageList = imageList;
          this.latitude = latitude;
          this.longitude = longitude;
          this.phonenumbers = phonenumbers;
          this.prepaid = prepaid;
          this.rentperiod = rentperiod;
          this.rentprice = rentprice;
          this.rooms = rooms;
          this.size = size;
          this.takeoverdate = takeoverdate;
          this.usagecost = usagecost;
          this.zipcode = zipcode;
  
          for (String s :imageList){
  
              URL myFileUrl = null;
              try {
                   myFileUrl= new URL(s);
              } catch (MalformedURLException e) {
                   e.printStackTrace();
              }
              try {
                   HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
                   conn.setDoInput(true);
                   conn.connect();
                   InputStream is = conn.getInputStream();
                   Bitmap image = BitmapFactory.decodeStream(is); //Saves the current icon
                   bigBitmapList.add(image);
                   //Icon will now be resized to 125px*100px               
                      Bitmap resized; 
                      int scalerate = (int)image.getHeight()/60;
                      int newHeight = (int)image.getHeight()/scalerate;
                      int newWidth = (int)image.getWidth()/scalerate; 
                      resized = Bitmap.createScaledBitmap(image, newWidth, newHeight, false);
                      smallBitmapList.add(resized);
              }
              catch (IOException e) {
                  e.printStackTrace();
              }
              }
          }
  
      public ApartmentParcel(Apartment ap){
          bigBitmapList = new ArrayList&lt;Bitmap&gt;();
          smallBitmapList = new ArrayList&lt;Bitmap&gt;();
          this.addeddate = ap.getAddeddate();
          this.deposit = ap.getDeposit();
          this.description = ap.getDescription();
          this.furniturized = ap.getFurniturized();
          this.id = ap.getId();
          this.imageList = ap.getImageList();
          this.latitude = ap.getLatitude();
          this.longitude = ap.getLongitude();
          this.phonenumbers = ap.getPhonenumbers();
          this.prepaid = ap.getPrepaid();
          this.rentperiod = ap.getRentperiod();
          this.rentprice = ap.getRentprice();
          this.rooms = ap.getRooms();
          this.size = ap.getSize();
          this.takeoverdate = ap.getTakeoverdate();
          this.usagecost = ap.getUsagecost();
          this.zipcode = ap.getZipcode();
          runMyParcel();
      }
  
      private void runMyParcel(){
          for (String s :imageList){
  
              URL myFileUrl = null;
              try {
                   myFileUrl= new URL(s);
              } catch (MalformedURLException e) {
                   e.printStackTrace();
              }
              try {
                   HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
                   conn.setDoInput(true);
                   conn.connect();
                   InputStream is = conn.getInputStream();
                   Bitmap image = BitmapFactory.decodeStream(is); //Saves the current icon
                   bigBitmapList.add(image);
                   //Icon will now be resized to 125px*100px               
                      Bitmap resized; 
                      int scalerate = (int)image.getHeight()/60;
                      int newHeight = (int)image.getHeight()/scalerate;
                      int newWidth = (int)image.getWidth()/scalerate; 
                      resized = Bitmap.createScaledBitmap(image, newWidth, newHeight, false);
                      smallBitmapList.add(resized);
              }
              catch (IOException e) {
                  e.printStackTrace();
              }
              }
      }
  
      public void setSmallBitmapList(ArrayList&lt;Bitmap&gt; smallBitmapList) {
          this.smallBitmapList = smallBitmapList;
      }
  
  
      @Override
      public int describeContents() {
          // TODO Auto-generated method stub
          return 0;
      }
  
  
      @Override
      public void writeToParcel(Parcel out, int flags) {
          out.writeString(id); 
          out.writeString(zipcode); 
          out.writeString(size); 
          out.writeString(rooms); 
          out.writeString(rentprice); 
          out.writeString(deposit); 
          out.writeString(takeoverdate); 
          out.writeString(rentperiod); 
          out.writeString(furniturized);
          out.writeString(usagecost);
          out.writeString(addeddate);
          out.writeString(description);
          out.writeString(prepaid);
          out.writeStringList(phonenumbers);
          out.writeList(bigBitmapList);
          out.writeList(smallBitmapList);
  
      }
  
      private ApartmentParcel(Parcel in) {
          id = in.readString();
          zipcode = in.readString();
          size = in.readString();     
          rooms = in.readString();
          rentprice = in.readString();
          deposit = in.readString();
          takeoverdate = in.readString();
          rentperiod = in.readString();
          furniturized = in.readString();
          usagecost = in.readString();
          addeddate = in.readString();
          description = in.readString();
          prepaid = in.readString();
          in.readStringList(phonenumbers);
          in.readTypedList(bigBitmapList, Bitmap.CREATOR);
          in.readTypedList(smallBitmapList, Bitmap.CREATOR);
      }
  
      public static final Creator&lt;ApartmentParcel&gt; CREATOR = new Creator&lt;ApartmentParcel&gt;() {
          public ApartmentParcel createFromParcel(Parcel in) {
              return new ApartmentParcel(in);
          }
  
          public ApartmentParcel[] newArray(int size) {
              return new ApartmentParcel[size];
          }
      };
  }
  </code></pre>
  
  <p>ApartmentInfoActivity.java :</p>
  
  <pre><code>    package com.android.madsoft.spotter;
  
      import android.app.Activity;
      import android.os.Bundle;
      import android.widget.TextView;
  
      public class ApartmentInfoActivity extends Activity {
  
  
          @Override
              protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.infoview);
  //      Apartment ap = (Apartment)getIntent().getSerializableExtra("apartment");
          Apartment ap = (Apartment)getIntent().getParcelableExtra("app");
          TextView zipView = (TextView)findViewById(R.id.txtInfoZip);
          zipView.setText(ap.getZipcode());
      }
  
      }
  </code></pre>