Why won't Intent pass along the extras

by frizzo » Wed, 11 Mar 2009 13:45:47 GMT

Sponsored Links
 I have a class object that I want to pass from one screen to another.
So I made it inherit from Parcelable and added the following code to
my class:

public class ItemDescription implements Parcelable {
       /// property setters and getters

        public int describeContents() {
                // TODO Auto-generated method stub
                return 0;

        public void writeToParcel(Parcel out, int flags) {

        public static final Parcelable.Creator<ItemDescription> CREATOR = new
Parcelable.Creator<ItemDescription>() {
        public ItemDescription createFromParcel(Parcel in) {
            return new ItemDescription(in);

        public ItemDescription[] newArray(int size) {
            return new ItemDescription[size];

In response to an event, I do kick off another screen (Intent) and put
extras into it:

        Intent mIntent = new Intent(v.getContext(), Item.class);

        Parcelable itemDesc = getItemDescription(preset);  // returns
        mIntent.putExtra("com.vbrad.android.mystapp.item1", itemDesc);

In the onCreate event of this new activity, I attempt o retrieve the
contents of the itemDesc object in the following manner:

        Intent intent = getIntent();
        Parcelable p = intent.getParcelableExtra("com.vbrad.android.
        ItemDescription itemDesc = (ItemDescription) p;

However, the itemDesc object is unpopulated - all the internal
variables are at default values (e.g. 0 for numeric types, null for
everything else).  It's like it was just created.

What am I missing here?



Why won't Intent pass along the extras

by Steven Farley » Wed, 11 Mar 2009 21:36:22 GMT

 I have done this succesfully with a Serializable object added with
Intent#putExtra(String, Serializable).  Is there some reason why
Parcelable is a better choice in your case?



Sponsored Links

Why won't Intent pass along the extras

by frizzo » Thu, 12 Mar 2009 13:26:03 GMT

 I have no idea whether it's a better choice or not.  I asked the
question here as to how to do it and was given Parcelable as the
answer.  I'll give it a try with serializable.


Why won't Intent pass along the extras

by frizzo » Thu, 12 Mar 2009 14:45:08 GMT

 Can you post an example by any chance?


Why won't Intent pass along the extras

by frizzo » Sat, 14 Mar 2009 12:35:11 GMT

 Serializable works.


Other Threads

1. import birthday dari facebook ke event calendar

jadi event birthday yang ada di FB bisa ke sync sama Google Calendar kita?
wah klo bisa bagus pisan euy.. ntar gw test ah.. masih liat2 doang tadi..
Nice share bro :)

Google Groups "Indonesian Android Community [id-android]" group.

To post to this group, send email to id-android@googlegroups.com

To request to subscribe to this group, please visit the following page:

2. samples from media pool never released by OMX MPEG-4 Video Decoder

seems i've found where i was wrong... question no more actual.

 Best regards,

unsubscribe: android-porting+unsubscr...@googlegroups.com

3. How does Android compute yaw,pitch,roll???

4. GeoCoder.getFromLocationName always return null??

5. Geocoder.getFromLocationName() vs bounding box?

6. Is it possible to override the sdcard using emulator from Eclipse (SDK 1.6, ADT 0.9.3) ?

7. Sockets with Android.