Passing around Strings and Integers in between activities can be done easily using Intents via the putExtras and getExtras methods, but if we need to pass object references we need to serialize them first.
Java offers a simple solution : Just implement the Serializable interface and Java will make its best effort to Serialize this class. This is simple and avoids a bunch of boilerplate code but is very bad for performance especially when we have 100’s of objects (A realistic case). The reasons why are as follows :
- Serialization uses reflection to learn the variables and method names. Reflection tends to be slow.
- Serialization also creates a lot of temporary variables thereby necessitates garbage collection, Which again will lead to noticeable jankiness in the UI based on when the GC is triggered.
Android decided this was too slow for the purposes of Android and implemented Parcelable which explicitly spells out how and which values need to serialized.