It looks like your Animal class is abstract and should never be
constructed. Declare Animal 'abstract' and see if you get an
instantiation error.

Have your tried to put the 'public static final Parcelable.Creator
CREATOR<Cat>' and 'public static final Parcelable.Creator
CREATOR<Dog>' variables and definitions in both Cat and Dog (and not
in Animal)? This will make sure that the factory-method
createFromParcel creates the appropriate subclass (Cat or Dog, and not
Animal).

About the readFromParcel().
If Cat and Dog both implement readFromParcel() it should work fine.
Are you sure that the variable 'a' is not an Animal instance?

On Jul 15, 10:39 am, Bart van Wissen <bartvanwis...@gmail.com> wrote:
> I just noticed that my workaround is not actually working. I did the
> following inside my Animal's CREATOR.createFromParcel:
>
> className = source.readString();
> a = (Animal) Class.forName(className).newInstance();
> a.readFromParcel(source);
>
> Now a has the right type (so Cat or Dog), but somehow still
> Animal.readFromParcel() is called.
> Aren't methods supposed to be "virtual" by default?
>
> On Jul 15, 4:11 pm, Bart van Wissen <bartvanwis...@gmail.com> wrote:
>
>
>
>
>
> > My current workaround is as follows:
> > - In each specific Animal subtype's writeToParcel() method, I write
> > the class name as a String into the Parcel as the first element.
> > - In the Animal's CREATOR.createFromParcel() I read the first String
> > out of the parcel, and based on that I create the appropriate type and
> > call the appropriate readFromParcel() method.
>
> > I think this is kind of ugly though. I would expect the android
> > framework to take care of this for me.
>
> > (My application is not actually dealing with animals, this is just to
> > make it simpler to explain the issue)- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to