Hey @ all!

I've got a question about Parcelling. I can't find the answer all over
the web, so you are my last hope ;)

I'll explain the problem by using an example.

These are my custom-objects:

public class Garden implements Parcelable {

int numberOfPlants;
Plant[] plants;

{...}

}

public class Plant implements Parcelable {}

public class Flower extends Plant implements Parcelable {}

public class Tree extends Plant implements Parcelable {}


Now, I'd like to send an instance of Garden from one Activity to
another.
So i have to parcel the plants[]-Array. This is possible as long as
the Array only includes instances of Plant.

My problem is that it seems to be impossible to parcel when plants[]
includes instances of Flower and Tree (subclasses of Plant) as well.
So, is it possible to do something like that?

Here's how I tried to do it (actually, I tried many more thing, but
now I am too confused to get them together :( ):

public Garden(Parcel in) {
        numberOfPlants = in.readInt();
        plants = new Plant[numberOfPlants];

        for (int i=0; i<numberOfPlants; i++) {
                //plants[i] = Plant.CREATOR.createFromParcel(in); (just another 
try)
                plants[i] = in.readParcelable(Plant.class.getClassLoader());
        }
}

public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(numberOfPlants);
        for (int i=0; i<numberOfPlants; i++) {
                plants[i].writeToParcel(dest, flags);
        }
}

Really hope you can help me.
Thanks in advance,

mj@gue

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to