title: How to use Parcel in Android?
body: <p>I'm trying to use <code>Parcel</code> to write and then read back a <code>Parcelable</code>.  For some reason, when I read the object back from the file, it's coming back as <code>null</code>.</p>
  
  <pre><code>public void testFoo() {
      final Foo orig = new Foo("blah blah");
  
      // Wrote orig to a parcel and then byte array
      final Parcel p1 = Parcel.obtain();
      p1.writeValue(orig);
      final byte[] bytes = p1.marshall();
  
  
      // Check to make sure that the byte array seems to contain a Parcelable
      assertEquals(4, bytes[0]); // Parcel.VAL_PARCELABLE
  
  
      // Unmarshall a Foo from that byte array
      final Parcel p2 = Parcel.obtain();
      p2.unmarshall(bytes, 0, bytes.length);
      final Foo result = (Foo) p2.readValue(Foo.class.getClassLoader());
  
  
      assertNotNull(result); // FAIL
      assertEquals( orig.str, result.str );
  }
  
  
  protected static class Foo implements Parcelable {
      protected static final Parcelable.Creator&lt;Foo&gt; CREATOR = new Parcelable.Creator&lt;Foo&gt;() {
          public Foo createFromParcel(Parcel source) {
              final Foo f = new Foo();
              f.str = (String) source.readValue(Foo.class.getClassLoader());
              return f;
          }
  
          public Foo[] newArray(int size) {
              throw new UnsupportedOperationException();
          }
  
      };
  
  
      public String str;
  
      public Foo() {
      }
  
      public Foo( String s ) {
          str = s;
      }
  
      public int describeContents() {
          return 0;
      }
  
      public void writeToParcel(Parcel dest, int ignored) {
          dest.writeValue(str);
      }
  
  
  }
  </code></pre>
  
  <p>What am I missing?</p>
  
  <p><strong>UPDATE:</strong>  To simplify the test I've removed the reading and writing of files in my original example.</p>