What is Serializable and Parcelable?

  • Thread starter Thread starter Ashish Bisht
  • Start date Start date
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
3 replies · 1K views
Ashish Bisht
Messages
2
Reaction score
0
Hi everyone, i am an Android developer and want to know your views on Serializable and Parcelable. Which is best approach in Android that will be helpful for me ?
 
Physics news on Phys.org
Serializable is a marker interface, that you implement on a class and its children. The downside of this approach is that it's slow and creates a lot of temporary objects.

Parcelable is a more specialized interface, which is significantly faster than Serializable. The downside is that you have to write some - enough in many cases, boilerplate code.

Everything has its cost. If you can afford the time , then it's better to use Parcelable. On the other hand, in most cases the slowness of Serializable - that is due to reflection that is used, won't be particularly noticeable, so you can write significantly less code and be OK. In general, you have to judge yourself on a per case basis, if it worths the extra time or not.

I strongly recommend to look up Android documentation, in order to have a complete view about the two choices.
 
Last edited:
  • Like
Likes   Reactions: harborsparrow and Ashish Bisht
Thank you everyone for valuable suggestion.