Android uses bundle to transfer objects through intent. Details
Android uses bundle to pass objects through intent
In Android development, it is sometimes necessary to transfer objects in applications or between processes. The following describes in detail the method of intent using bundle to transfer objects.
The passed object needs to be serialized first, and there are two ways to serialize the object: Java io. Serializable and Android os. Parcelable
Serializable is used in Java, while Google uses a custom Parcelable in Android.
Differences between the two serialization methods:
1. When using memory, Parcelable has higher performance than serializable. It is recommended to use Parcelable class; 2. Serializable will generate a large number of temporary variables during serialization, resulting in frequent GC; 3. Parcelable cannot be used when the data is to be stored on the disk, because Parcelable cannot guarantee the continuity of the data well. In case of external changes,
Serializable is recommended in this case.
Step 1: define serialization entity class;
Serializable mode:
Parcelable mode:
Step 2: pass the serialized object;
Step 3: get the object;
Attached source code: download address
Screenshot of operation results:
Thank you for reading, hope to help you, thank you for your support to this site!