regarding my code example down, what shold I do if one Locable\'s variables is null? In example, now if l.getZoom() returns null, I got NullPointerException.
I'm using a Parcelable
class that has Integer
and Boolean
fields as well, and those fields can be null.
I had trouble using the generic Parcel.writeValue
method, particularly when I was trying to read it back out via Parcel.readValue
. I kept getting a runtime exception that said it couldn't figure out the type of the parceled object.
Ultimately, I was able to solve the problem by using Parcel.writeSerializable
and Parcel.readSerializable
with a type cast, as both Integer
and Boolean
implement the Serializable interface. The read and write methods handle null
values for you.