5

I want to pass objects between Activities and Services on Android. The straight forward way to do this is to make your objects implement Serializable or Parcelable.

  • Serializable it's relatively bad performance.
  • Parcelable on the other hand requires me to implement and maintain the serialization myself i.e. always to remember to update it in the future.

I was thinking about using Jackson Json serializer for this task. It's faster than Java built in serialization and does not require me write and maintain serializtion code.

What you think?

AlexV
  • 3,836
  • 7
  • 31
  • 37

2 Answers2

2

I believe both the methods have its own importance.

  • Parcelable is a good choice. But using parcelable you will have to write code for serialization yourself. This method is not encouraged when you are having large number of data members in your class, whose object you want to send.
  • On the other hand serialization is for sure bulky operation but I think easy to implement. You will have to make your class implements serializable.

But still there is one more option, which you can use. You can make your object static and access it from other Activity. if object is not a lot bulky, then this is also good choice.

halfer
  • 19,824
  • 17
  • 99
  • 186
N-JOY
  • 10,344
  • 7
  • 51
  • 69
2

If performance is important, then you really should go with Parcelable. JSON will be relatively slow because it is less efficient than Parcelable which was specifically implemented in Android for improving performance when packaging data for Inter-Process Communication.

Mark Allison
  • 21,839
  • 8
  • 47
  • 46
  • This is true, android uses Active Objects (Binder or FileDescriptors) instead of the old-fashioned flattening – Reno Jun 14 '11 at 09:40
  • 1
    Thanks for the answer. How is Parcelable compared to Externalizable? Speed, Memory? – AlexV Jun 14 '11 at 12:44
  • Does anyone know what sorta relative difference there would be in using parcelable vs JSON just to save complex objects in save state? – Zachary Moshansky Oct 23 '12 at 21:25