Serializable () and Parcelable ()

5

I do not understand very well the use of Parcelable() and Serializable() .

What is the difference between Serializable() and% Parcelable() ?

In which cases can I use a Parcelable and in which% Serializable ?

    
asked by Ramosaurio 11.08.2016 в 13:22
source

2 answers

3

Parcelable , is much faster than Serializable since is optimized for use on Android, the interface created by Google is android.os.Parcelable , in terms of implementation it will probably take you longer compared to Serializable, but you will get better benefits.

Serializable , is slower compared to Parcelable. Use the java standard interface, for this reason its implementation is more simple compared to Parcelable. An important feature is that a Parcelable arrangement can be sent through an Android intent. An unfavorable feature may be that Serializable creates many objects in memory, although they are temporary, it can cause a little Garbage Collecting .

If you are developing on Android as your question indicates, the option is to use Parcelable

I add a comparison table of tests where you can compare the speed of both interfaces.

source: Parcelable vs Serializable (English)

    
answered by 11.08.2016 / 16:48
source
4

The best thing about Serializable() is that only the interface is needed and Java takes care of doing it the best it can.

With Parcelable() you will do better on android, since it is much faster and more efficient since it is made specifically for Android.

I leave you some information that will help you;) link

    
answered by 11.08.2016 в 14:18