Bundle.putparcelable can implement passing objects, but the object's class must implement the Parcelable interface before it can be used.
Here is a simple example of passing an object between the activity.
Parcel realizes the serialization of parameters and serializes the class objects into homogeneous binary streams to improve the efficiency of transmission.
Parcelable class. The main class, which is the class of the object we are transferring, needs to implement the Parcelable interface.
import Android.os.Parcel;
Import android.os.Parcelable;
public class Benparcelable implements parcelable {public String name;
public int age;
public String profession;
Public benparcelable (string name, int age, string profession) {this.name = name;
This.age = age;
This.profession = profession;
Public String GetName () {return name;
public void SetName (String name) {this.name = name;
public int getage () {return age;
public void Setage (int age) {this.age = age;
Public String getprofession () {return profession;
} public void Setprofession (String profession) {this.profession = profession;
} @Override public int describecontents () {return 0; @Override public void Writetoparcel (Parcel Parcel, int flag) {parcel.writestring (name)
;
Parcel.writeint (age);
Parcel.writestring (profession);
public static final creator<benparcelable> Creator = new Creator<benparcelable> () {
Public benparcelable Createfromparcel (Parcel in) {Return to New benparcelable (in);
Benparcelable[] NewArray (int size) {return new benparcelable[size];
}
};
Private benparcelable (Parcel in) {name = In.readstring ();
Age = In.readint ();
profession = in.readstring (); }
}