I've run into the following issue:

Say I have an Animal class, which is parcelable, and I have a Dog
class and a Cat class, which are subclasses of Animal and also
implement Parcelable.

Say I have a service with the following AIDL interface:

sendAnimals(List<Animal> animals);

Now I'm calling this remote interface from some client application,
passing it a List containing Cats and Dogs. What happens now is that
android calls the Cat's and the Dog's writeToParcel() methods at the
client side, but at the server side, the Animal's CREATOR is used,
which calls Animal's readFromParcel() method.
So the right data is sent from the client, but the wrong unmarshalling
code is executed at the server.


I have tried to put this in the AIDL file:

sendAnimals(List<T extends Animal> animals);

This results in a syntax error from the aidl compiler though.

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)
--~--~---------~--~----~------------~-------~--~----~
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