We know that in Android, bundle or intent can be used to store and transmit data. Sometimes, because of some program needs, we may need to pass a variety of custom objects. It is not enough to pass only simple types of data. However, these objects cannot be directly transmitted between activities. How can this problem be solved?
Method 1: A public class is used as the object transmission intermediary, but the security is poor. The transmission may fail due to the call of multiple classes.
Write the variable as a public static type and set center. A = new in a Activiy.
Obiect () receives object B = center. A in B Activiy, for example:
Public
Class center {
Public static object
A;
}
Method 2: Implement interface serializable
Implement the serializable interface.
Method 3: Implementation interface parcelable
You need to implement the parcelable interface and its method, write the object attribute in the writetoparcel () method, add the public static variable creator, and read the object attribute here.