Android studio 将类的arraylist传递给Android Studio中的另一个活动
//这是我的课Android studio 将类的arraylist传递给Android Studio中的另一个活动,android-studio,arraylist,Android Studio,Arraylist,//这是我的课 private String name; private int height; private float weight; private int age; private Sex gender; public String getName() { return name; } public int getHeight() { return height; } public float getWeight() { return weight; }
private String name;
private int height;
private float weight;
private int age;
private Sex gender;
public String getName() {
return name;
}
public int getHeight() {
return height;
}
public float getWeight() {
return weight;
}
public int getAge() {
return age;
}
public Sex getGender() {
return gender;
}
public enum Sex {male, female, others}
;
public User(String name, Sex gender, int age, float weight, int height) {
this.name = name;
this.gender = gender;
this.age = age;
this.weight = weight;
this.height = height;
}
}
这是从第一个活动开始的
ArrayList<User> userList = new ArrayList<User>();
Intent intent = new Intent(ProfileSelect.this,MainActivity.class);
intent.putExtra("list",userList);
startActivity(intent);
ArrayList userList=new ArrayList();
意向意向=新意向(ProfileSelect.this,MainActivity.class);
intent.putExtra(“列表”,用户列表);
星触觉(意向);
现在我想向另一个名为mainactivity的活动显示userlist。如何在mainactivity中检索列表?
提前进行全面质量检查 您可以使用
// Post Object
EventBus.getDefault().postSticky(yourObject);
// Get Object
YourClass yourObject = EventBus.getDefault().getStickyEvent(YourClass.class);