0

Normally in Java I would encapsulate many objects into a serializeable bean. Then work with the objects stored in the bean, and pass the bean around my application.

https://en.wikipedia.org/wiki/JavaBeans

The problem is that a lot of google's objects are declared final, and don't implement serializeable, such as a LatLng object. This means that I can't extend them and implement serializeable, or include them in my bean.

Instead they implement parcelable. Maybe I could make my beans parcelable. The problem with this is that I seem to spend a lot of time debugging unmarshalling exceptions at runtime. Also I have a few final objects that only implement serializeable.

Another alternative is to use a Bundle. This takes both serializeable and parcelable objects separately, but references them using strings, so it's not as nice to use as a bean, which knows the objects that it contains.

What is the best way of doing this?

UEFI
  • 243
  • 1
  • 2
  • 10
  • I often put similar objects in a custom Application class, which acts like a singleton and can be referenced from almost anywhere in my app. – AutonomousApps Jul 31 '15 at 12:26
  • You could try Parceler, which handles the marshaling and unmarshaling code for you. https://github.com/johncarl81/parceler – nasch Jul 31 '15 at 15:45

0 Answers0