I am not clear about distinct use of interface Serializable
and Parcelable
in Android. If we prefer the use of Parcelable
, then why we do so over Serializable
. Moreover, if I pass data through any webservice, can Parcelable
help? If so, then how?
Asked
Active
Viewed 53 times
0

Jared Rummler
- 37,824
- 19
- 133
- 148

atifali
- 193
- 16
-
1Possibly duplicate check this http://stackoverflow.com/questions/3323074/android-difference-between-parcelable-and-serializable – Sunil Sunny Aug 25 '15 at 06:38
1 Answers
2
So the main difference is the speed, and it matters on your hand-held device. Supposedly less powerful than your desktop.
With Serialisable
which comes for goold old Java, your code will look like this:
class MyPojo implements Serializable {
String name;
int age;
}
No extra methods are needed as reflection
will be used to get all fields and their values. And this can me slow or is slower than ...
and to use Parcelable
you have to write something like this:
class MyPojo implements Parcelable {
String name;
int age;
MyPojo(Parcel in) {
name = in.readString();
age = in.readInt();
}
void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
dest.writeInt(age);
}
int describeContents() {
return 0;
}
// and here goes CREATOR as well and what not
};
according to guys @google it can be much much faster, Parcelable
s that is.
Of course, there are tools to help you with adding all necessary fields to make a class Parcelable
like https://github.com/johncarl81/parceler

pelotasplus
- 9,852
- 1
- 35
- 37