Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's different of putSerializable and putParcelable in Java?

Hi I'm beginner developer of Android :) I want to send ArrayList<Custom> value from Activity to Fragment. I know that have to use Bundle, but I don't know what's method can help me.

  1. What is different of putSerializable and putParcelable?
  2. In my situation, Which method can help me putParcelableArrayList or putSerializable?

Thanks all that give me opportunity to grow :)

like image 380
Soyeon Kim Avatar asked Jul 31 '15 08:07

Soyeon Kim


2 Answers

Serializable and Parcelable are both an interface. The former is as ancient as java. It allows you to store/write an object in a persistent way. The beauty of it is that you just have to implement the interface. The latter, Parcelable, is android specific. It is faster than Serializable, but you will have to implement the method of the interface to be able to use it.

What is different of putSerializable and putParcelable

putSerializable accepts objects that implement Serializable, putParcelable accepts objects that implement Parcelable

In my situation, Which method can help me putParcelableArrayList or putSerializable?

It is difficult to say. Generally speaking I would say Parcelable

like image 114
Blackbelt Avatar answered Sep 19 '22 13:09

Blackbelt


Generally speaking, Parcelable are way more faster than Serializable. Here is a great article if yout want to learn more about it http://www.developerphil.com/parcelable-vs-serializable/

like image 24
skamlet Avatar answered Sep 19 '22 13:09

skamlet