title: Android Parcelable object not passing properly between activities
body: <p>This has been taxing my mind for the past two days. Oddly, the code works fine in one project, when passing an object from activity to fragment, but I cannot make this object pass from activity to activity, even when I appear to be implementing parcelable properly.</p>
  
  <p>Oddly, I don't get a null object at the other end, but the object has got null values within it.</p>
  
  <p>I've created a new project to test this with. This is the code so far:</p>
  
  <p>MainActivity.java:</p>
  
  <pre><code>    package com.example.parcleableexample;
  
      import android.os.Bundle;
      import android.app.Activity;
      import android.content.Intent;
      import android.view.Menu;
      import android.view.View;
      import android.widget.TextView;
  
      public class MainActivity extends Activity {
          Site mySite = new Site();
  
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
              mySite.setSiteName("hi");
              TextView myText = (TextView) findViewById(R.id.txtSiteName);
              myText.setText(mySite.getSiteName());
          }
  
          @Override
          public boolean onCreateOptionsMenu(Menu menu) {
              // Inflate the menu; this adds items to the action bar if it is present.
              getMenuInflater().inflate(R.menu.main, menu);
              return true;
          }
  
  
          public void doThing (View v) {
              Intent mIntent = new Intent(this,AnotherActivity.class);
              mIntent.putExtra("site", mySite);
              startActivity(mIntent);
          }
      }
  </code></pre>
  
  <p>AnotherActivity.java:</p>
  
  <pre><code>package com.example.parcleableexample;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.widget.TextView;
  
  public class AnotherActivity extends Activity {
  
      Site mySite = new Site();
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
              mySite = getIntent().getParcelableExtra("site");
              TextView myText = (TextView) findViewById(R.id.txtSiteName);
              myText.setText(mySite.getSiteName());
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  }
  </code></pre>
  
  <p>Site.Java:</p>
  
  <pre><code>package com.example.parcleableexample;
  
  import android.os.Parcel;
  import android.os.Parcelable;
  
  public class Site implements Parcelable {
  
      private String siteName;
  
      Site() {
          // Empty Constructor
      }
  
      public String getSiteName() {
          return siteName;
      }
  
      public void setSiteName(String siteName) {
          this.siteName = siteName;
      }
  
      // Parcleable Functions:
      private int mData;
      public int describeContents() {
          return 0;
      }
  
      public void writeToParcel(Parcel out, int flags) {
          out.writeInt(mData);
      }
  
      public static final Parcelable.Creator&lt;Site&gt; CREATOR = new Parcelable.Creator&lt;Site&gt;() {
          public Site createFromParcel(Parcel in) {
              return new Site(in);
          }
  
          public Site[] newArray(int size) {
              return new Site[size];
          }
      };
  
      private Site(Parcel in) {
          mData = in.readInt();
      }
  }
  </code></pre>
  
  <p>activity_main.xml:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context=".MainActivity" &gt;
  
      &lt;TextView
          android:id="@+id/txtSiteName"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/hello_world" /&gt;
  
      &lt;Button
          android:id="@+id/button1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/txtSiteName"
          android:layout_below="@+id/txtSiteName"
          android:layout_marginLeft="42dp"
          android:layout_marginTop="25dp"
          android:onClick="doThing"
          android:text="Button" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>What I would expect, is for the "hi" value to appear both times, once when I start the app, and again when I click the button and the new activity creates.</p>
  
  <p>However, it's only showing correctly the first time, the second time the getSiteName only returns null.</p>
  
  <p>I also copied and pasted the Site object directly from the working app, with the same result, but it works in the working app as expected; the Site object is copied properly.</p>
  
  <p>The working app runs this code:</p>
  
  <pre><code>Bundle arguments = new Bundle();
  arguments.putParcelable("site", SearchResults.get(position));
  ViewSiteFragment myFragment = new ViewSiteFragment();
  myFragment.setArguments(arguments);
  FragmentTransaction myTransaction = getFragmentManager().beginTransaction();
  myTransaction.replace(R.id.MainFragmentContainer, myFragment);
  myTransaction.addToBackStack(null);
  myTransaction.commit();
  </code></pre>
  
  <p>And picks up the object at the other end here:</p>
  
  <pre><code>Site mSite = getArguments().getParcelable("site");
  </code></pre>
  
  <p>I know I'm doing something wrong... Just haven't got a clue what I've missed!</p>