我想将对象从一个类传递到另一个类,我的代码是
private MemberLoginResponse loginResponse;
.
.
Intent intent = new Intent();
intent = new Intent(context, BillingDeskActivity.class);
intent.putExtra("privilages", loginResponse);
startActivity(intent);
在接收数据的其他活动中,我使用此代码
Intent i_privilages = getIntent();
privilages = (MemberLoginResponse) getIntent().getSerializableExtra("privilages");
甚至我保留了我的班级实现可序列化
我在声明 arraylist 时击中 ed 的班级
public class MemberLoginResponse implements Parcelable {
public Integer merchantMemberId = 0;
public Integer merchantId = 0;
public String merchantName = "";
public String merchantLogo = "";
public String merchantType = "";
public String merchantHQAddress = "";
public List<CustomSystemPrivilege> merchantPrivileges;
public List<CustomSystemPrivilege> privileges;
public StatusCode statusCode;
public Integer branchId = 0;
public MemberLoginResponse(Parcel in) {
merchantMemberId = in.readInt();
merchantId = in.readInt();
merchantName = in.readString();
merchantLogo = in.readString();
merchantType = in.readString();
merchantHQAddress = in.readString();
in.readList(merchantPrivileges,
CustomSystemPrivilege.class.getClassLoader());
in.readList(privileges, CustomSystemPrivilege.class.getClassLoader());
branchId = in.readInt();
}
public MemberLoginResponse() {
// TODO Auto-generated constructor stub
}
public static final Parcelable.Creator<MemberLoginResponse> CREATOR = new Parcelable.Creator<MemberLoginResponse>() {
@Override
public MemberLoginResponse createFromParcel(Parcel in) {
return new MemberLoginResponse(in);
}
@Override
public MemberLoginResponse[] newArray(int size) {
return new MemberLoginResponse[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(merchantMemberId);
dest.writeInt(merchantId);
dest.writeString(merchantName);
dest.writeString(merchantLogo);
dest.writeString(merchantType);
dest.writeString(merchantHQAddress);
dest.writeList(merchantPrivileges);
dest.writeList(privileges);
dest.writeInt(branchId);
}
} }