list = new ArrayList<String>();
in.readStringList(list);
不建议使用在需永久保存的数据
public class User implements Parcelable{
private int id;
private String name;
protected User(Parcel in) {
id = in.readInt();
name = in.readString();
}
public static final Creator<User> CREATOR = new Creator<User>() {
@Override
public User createFromParcel(Parcel in) {
return new User(in);
}
@Override
public User[] newArray(int size) {
return new User[size];
}
};
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeString(name);
}
}
Parcel的写入和读取顺序是一致的如果元素是list,读取时需要传入一个ArrayList,否则会报空指针异常 list = new ArrayList&lt;String&gt;();in.readStringList(list);不建议使用在需永久保存的数据public class User implements Parcelable{ private int id; p...