[Jderobot] Always Parcelable, never Serializable (in Android)

jde-developers jde-developers en gsyc.es
Jue Jul 18 08:45:17 CEST 2013


Jderobot, technology that rocks has posted a new item, 'Always Parcelable, never
Serializable (in Android)'

The final conclusion of Android Team is that Serializable in JAVA is far too
slow to satisfy Android’s interprocess-communication requirements. So the
team built the Parcelable solution. Just read this sentence is enough to forget
Serializable mechanism. But, I want to show you how the faster is Parcelable in
comparison with Serializable. We are going to measure the time it takes to pass
a structure in Android using the intent when we start a new activity.
We have around 340 nodes into ArrayList structure. Each node is a simple class
that contains two String attributes and one Double attribute.

1
2
3
4
5
public class Foo  //implements Parcelable or Serializable
	private String mVar1;
	private Double mVar2
	private String mVar3;


This is the way how we pass the date if the structure is Serializable

1
2
3
4
5
6
7
8
9
// Code of Activity1
ArrayList array = fillArray
Intent popupIntent = new Intentthis, Activity2.class
popupIntent.putExtrakey_array, array
startActivitypopupIntent

// Code of Activity2
Intent i = getIntent
ArrayList array = i.getSerializableExtrakey_array

And this is the way how we pass the date if the structure is Parcelable

1
2
3
4
5
6
7
8
9
//Code of Activity1
ArrayList array = fillArray
Intent popupIntent = new Intentthis, Activity2.class
popupIntent.putParcelableArrayListExtrakey_array, array
startActivitypopupIntent

//Code of Activity2
Intent i = getIntent
ArrayList array = i.getParcelableArrayListExtrakey_array

Finally, you can see the times of this experiment. Ive measured the time it
takes to pass the structure in both cases (Serializable and Parcelable). The
results are overwhelming.


Elements
Serializable Time(ms)
Parcelable Time(ms)



340
3134
231


332
2708
157


342
3360
159


341
3151
186



We can conclude that Parcelable is around 15 times faster than Serializable!!
Implement parcelable structure requires a little effort because is needed
implement two methods for the serialization of the object, but its highly
recommended do it.

You may view the latest post at
http://blog.jderobot.org/always-parcelable-never-serializable-in-android/

You received this e-mail because you asked to be notified when new updates are
posted.
Best regards,
jde-developers
jde-developers en gsyc.es



More information about the Jde-developers mailing list