3

Why is it always advised to implement Parcelable instead of Serializable and in what situations is the latter better to use?

Gopal Gopi
  • 11,101
  • 1
  • 30
  • 43
u3l
  • 3,342
  • 4
  • 34
  • 51

2 Answers2

2

I think Parcelable is the same as Externalizable introduced in JAVA 1.1. So, it is good known approach how to serialize objects.

What is the difference between Serializable and Externalizable in Java?

Generally, downsides of Serializable are performance and performance. As is said in the answer from the link. You can use a 3th party implementations which are a bit faster. But it will be never as fast as externalizable.

Externalizable or Parcerable leverage from explicit definition how to load and store your objects. The problem is you should maintain a version of object to know what logic to use to serialize or deserialize your objects. There could be a problem with backward compatibility and the programming work is much slower to it this (the right :)) way. But when we come to run-time this approach it's much faster.

Community
  • 1
  • 1
Milan Baran
  • 4,133
  • 2
  • 32
  • 49
  • No need for Externalizable. Manual serialization can be done with Serializable only. The bottom line is that Serializable is actually much faster on Android, but only if you use readObject() / writeObject(). So no need to use proprietary API like Parcelable, it is even slower than good old Serializable. – afrish Apr 07 '15 at 13:44
1

Java Serializable:- Serializable comes from standard Java and is much easier to implement all you need to do is implement the Serializable interface and add override two methods. The problem with Serializable is that it tries to appropriately handle everything under the sun and uses a lot reflection to make determine the types that are being serialized. So it becomes a beefy Object.

Androids Parcelable:- Android Inter-Process Communication (AIPC) file to tell Android how is should marshal and unmarshal your object.It is less generic and doesn't use reflection so it should have much less overhead and be a lot faster

Sanjeev
  • 9,876
  • 2
  • 22
  • 33