title: How can I send an object from one Activity to another with Intent.putExtra and Parcel?
body: <p>Using Stack Overflow question <em><a href="https://stackoverflow.com/questions/2139134/how-to-send-an-object-from-one-android-activity-to-another-with-intent-putextra">How to send an object from one Android Activity to another using Intents?</a></em>, I have made a sample application as follows.</p>
  <h3>File <em>Scrollview1.java</em></h3>
  <pre><code>import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  
  public class Scrollview1 extends Activity {
      static int i;
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          Button b = (Button)findViewById(R.id.Button01);
  
          b.setOnClickListener(new OnClickListener() {
  
              public void onClick(View v) {
                  Intent i = new Intent(Scrollview1.this, Result.class);
                  Name n = new Name();
                  n.setI(20);
                  n.setS1(&quot;Hello&quot;);
                  n.setS2(&quot;World&quot;);
                  i.putExtra(&quot;Name&quot;, n);
                  startActivity(i);
              }
          });
      }
  }
  </code></pre>
  <h3>File <em>Name.java</em></h3>
  <pre><code>import android.os.Parcel;
  import android.os.Parcelable;
  
  public class Name implements Parcelable {
      int i;
      String s1;
      String s2;
  
      public Name() {
  
      }
  
      private Name(Parcel in) {
          in.readInt();
          in.readString();
      }
  
      public int getI() {
          return i;
      }
  
      public void setI(int i) {
          this.i = i;
      }
  
      public String getS1() {
          return s1;
      }
  
      public void setS1(String s) {
          this.s1 = s;
      }
  
      public String getS2() {
          return s2;
      }
  
      public void setS2(String s) {
          this.s2 = s;
      }
  
      public int describeContents() {
          return 0;
      }
  
      public void writeToParcel(Parcel dest, int flags) {
          dest.writeInt(i);
          dest.writeString(s1);
          dest.writeString(s2);
      }
  
      public static final Name.Creator&lt;Name&gt; CREATOR = new Name.Creator&lt;Name&gt;() {
          public Name createFromParcel(Parcel in) {
              return new Name(in);
          }
  
          public Name[] newArray(int size) {
              return new Name[size];
          }
      };
  }
  </code></pre>
  <h3>File <em>Result.java</em></h3>
  <pre><code>import android.app.Activity;
  import android.os.Bundle;
  
  public class Result extends Activity {
      @Override
      public void onCreate(Bundle savedInstanceState) {
  
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
  
         Name a = (Name)getIntent().getParcelableExtra(&quot;Name&quot;);
         System.out.println(&quot;Int: &quot; + a.getI());
         System.out.println(&quot;String: &quot; + a.getS1());
         System.out.println(&quot;String: &quot; + a.getS2());
      }
  }
  </code></pre>
  <p>But it is Result class I getting null. What is wrong?</p>