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. Urgent: Getting error when uploading apk file on android market

Hi, i m uploading my apk for 1st time on market and getting Error:The
server could not process your apk. Try .
My manifest file is:-

`<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      <uses-permission android:name="android.permission.INTERNET">
    <application android:icon="@drawable/iccicon"
android:label="@string/app_name" android:debuggable="false">
        <activity android:name=".Activity1"
                <action android:name="android.intent.action.MAIN" />
android:name="android.intent.category.LAUNCHER" />
        <activity android:name=".Activity2"
    <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="4"/>
    <uses-configuration android:reqHardKeyboard="true"

Please help.


2. Samsung Spica -- I570EXXJCB bermasalah dengan GPRS/3G ? -- solved, thanks everybody

hoom David, thanks infonya...ternyata setting kmrn sudah cukup (cukup
set apn name=indosatgprs, user=indosat, password=indosat).

Yang bikin masalah ternyata kombinasi flashing yang salah.
Kemarin saya pakai bootloader dan phone firmware dari bawaan
I570EDDJB2(ini yang bermasalah). Seharusnya pakai bootloader dan phone
--> Thanks to [id-android], saya nemu url ini di forum ini.
(tips buat yang kesulitan download dari www.times.lv, pakailah
CSC sudah benar dari bawaan I5700DXJB3.
Setelah diflash lagi dng kombinasi yg benar, setting APN yang sama
konek dengan mulus ..

Saya sampai flashing ulang mungkin lebih dari 5 kali untuk confirming
di mana masalahnya...
Hebat juga ya Samsung diabuse gitu nggak juga ngebrick :)

cc. mas Muh Fitrah, saya tidak tahu soal IM2.. tetapi dia pakai
jaringan indosat.
Apakah anda sudah mencoba pakai kartu IM3 ? Jika dng settingan APN di
atas masih belum konek, mungkin kita mengalami problem yang sama...

cheers and thanks everybody,


> > Join:

3. BT plugging/unplugging issue on Eclair

4. Mohon Bantuannya Milestone saya matot

5. Reverse Tethering: Have Android phone use attached computer's connection

6. X10 gives multitouch fans the finger, 2 not supported

7. Is SoundPool really low latency?