First, pass the list
1. Ways to pass List<string>
arraylist<string> info = new arraylist<string> ();
Info.add (Weibo);
Intent Intent = new Intent (mainactivity.this, Resultactivity.class);
Intent.putstringarraylistextra ("infolist", info);
StartActivity (Intent);
Receive
arraylist<string> infolist = new arraylist<string> ();
Infolist = Getintent (). Getstringarraylistextra ("Infolist");
2. Ways to pass List<integer>
Intent.putintegerarraylistextra (key, list);
List = (arraylist<integer>) getintent (). Getintegerarraylistextra (key);
Two., passing object
1. Using the Serializable method
Premise: Object needs to implement serializable interface
The syntax for passing object in serializable mode: bundle.putserializable (Key,object);
The syntax for receiving object in serializable mode: object= (object) getintent (). Getserializableextra (key);
The implementation of the serializable interface is to serialize the object, and then transfer, and Java's common programming is no obvious difference, and object does not need to change significantly, recommended in this way.
Serinfo serinfo = new Serinfo (name, website, Weibo);
Intent Intent = new Intent ();
Bundle bundle = new bundle ();
Bundle.putserializable ("Serinfo", serinfo);
Intent.setclass (Mainactivity.this, Resultactivity.class);
Intent.putextras (bundle);
StartActivity (Intent);
Get the value of the serializable method passed over
Serinfo Serinfo = (serinfo) getintent (). Getserializableextra ("Serinfo");
2. Using the Parcelable method
Premise: Object needs to implement Parcelable interface
The syntax for passing object in parcelable mode: bundle.putparcelable (Key,object);
The syntax for receiving object in parcelable mode: object= (object) getintent (). Getparcelableextra (key);
The class that implements the Parcelable interface is more complex, what parcelable is a thing?
Iii. Transmission of List<object>
arraylist<serinfo> listobj = new arraylist<serinfo> ();
Serinfo serInfo1 = new Serinfo (name, website, Weibo);
Serinfo SerInfo2 = new Serinfo (name, website, Weibo);
Listobj.add (SERINFO1);
Listobj.add (SerInfo2);
Intent Intent = new Intent ();
Intent.setclass (Mainactivity.this, Resultactivity.class);
Intent.putextra ("Listobj", (Serializable) listobj);
StartActivity (Intent);
Get the list<object>.
Arraylist<serinfo> listobj = (arraylist<serinfo>) getintent (). Getserializableextra ("LISTOBJ");
Intent ways to pass data