The intent transitive class object in Android provides two ways of passing an object by implementing the Serializable interface, and one is passing an object by implementing the Parcelable interface.
The object required to be passed must implement one of the above 2 interfaces to pass directly through the intent.
Methods for passing these 2 kinds of objects in intent:
Bundle.putserializable (key,object); Implements the Serializable interface object Bundle.putparcelable (Key, object); Objects that implement the Parcelable interface
The following are examples of the most common serializable methods:
Assume that the user information that is passed by the login interface (login) to the main interface (mainactivity) is logged in the Users class
First create a serialization class: User
Importjava.io.Serializable;PublicClass UserImplementsSerializable {PrivateIntID;PrivateString UserName;PrivateString PWD;PublicFinalvoid SetID (IntValue) {ID =Value }PublicFinalIntGetID () {ReturnID; }public final void Setusername (String value) {UserName = value;} public final String GetUserName () {return UserName;} public final void value;} public final String Getpwd () {return PWD;}}
Login form to pass content after login
New Intent (); Intent.setclass (Login. This, mainactivity. classnew Bundle (); Bundle.putserializable ("User", user); Intent.putextras (bundle) ; This.startactivity (intent);
Receiving end
This. Getintent (); user= (user) Intent.getserializableextra ("user");
The above can achieve the object delivery.
Add:
If List<object> is passed, the list can be strongly converted to the serializable type, and the Object type must also implement the Serializable interface
Intent.putextras (Key, (Serializable) list)
Receive
(list<yourobject>) Getintent (). getserializable (Key)
Android Development Notes-passing class objects via Intent