On 5 October 2011 15:09, Jean-Michel <jeanmichel.caz...@gmail.com> wrote:
> Hi there,
> I am hitting a brickwall with serialization of a subclass of Location
> (probably more a Java question actuall, but let's try anyway).
>
> Location is not serializable.
> I have a first subclass called FALocation that does not have any
> instance variables. I have declared it serializable.


You cannot do that in Java. Implementing serializable subclass of
non-serializable super class will blow out, simply because to
de-flatten the object back, you need to create its superclass, but it
did not get serialized (since it's not serializable). A bit recursive
explanation, but I hope you understand. Here is, what serializable
class has to do, to fulfil the contract:

- Implement the Serializable interface.
- Make sure that instance-level, locally defined state is serialized properly.
- Make sure that superclass state is serialized properly.
- Override equals( ) and hashCode( ).

You skipped the 3rd point.

Now luckily for you, Location in Android implements Parcelable
interface, which could be of help, depending where are you sending to
and receiveing from your Leg/Location related data.
If it is within the same machine between a service and an activity,
then you are fine.  If you are passing it via network, you need to
implement a DTO, that implements Serializeable and holds all the
necessary data that you depend on. You then pass that DTO and with its
help you create new Location object at the receiving end.

HTH

-- 
Daniel Drozdzewski

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