In Android, it is often necessary to pass a value or object from one activtity to another activity.
First of all, there is a class, this class must go to implement Serializable; The code is as follows
public class Student implements serializable{String name;}
In the first activity, the object is passed as a value in intent, and the code is as follows
Intent Intent = new Intent (mainactivity.this,secondactivity.class); Student s = new Student (); s.name = "Wahaha"; Intent.putextra ("Stu", s); startactivity (intent);
To receive this object in the second activity.
TextView = (TextView) Findviewbyid (R.id.textview); Intent Intent = Getintent (); Serializable extra = Intent.getserializableextra ("Stu"); Student s = new Student (); String SName = null;//If the downward transition to Student class if (extra instanceof Student) {//Forced transformation SName = ((Student) extra). Name;} Textview.settext (SName);
So the object is passed over.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android passes an object from one activity to another activity