序列化bean为了两个Activity之间list传值
package com.zdy.edu.help;
import android.os.Parcel;
import android.os.Parcelable;
/**
* 获取通知通讯录分组工具类 序列化为了两个Activity之间list传值
* @author admin
*
*/
public class NoticeAddress implements Parcelable {
private String id;
//分组名
private String groupName;
//用户数
private String userCount;
//分组类型 Cls 班级分组 Dep 部门分组
private String groupType;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public String getUserCount() {
return userCount;
}
public void setUserCount(String userCount) {
this.userCount = userCount;
}
public String getGroupType() {
return groupType;
}
public void setGroupType(String groupType) {
this.groupType = groupType;
}
public NoticeAddress(String id, String groupName, String userCount,
String groupType) {
super();
this.id = id;
this.groupName = groupName;
this.userCount = userCount;
this.groupType = groupType;
}
public NoticeAddress() {
super();
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.id);
dest.writeString(this.groupName);
dest.writeString(this.userCount);
dest.writeString(this.groupType);
}
protected NoticeAddress(Parcel in) {
this.id = in.readString();
this.groupName = in.readString();
this.userCount = in.readString();
this.groupType = in.readString();
}
public static final Creator<NoticeAddress> CREATOR = new Creator<NoticeAddress>() {
@Override
public NoticeAddress createFromParcel(Parcel source) {
return new NoticeAddress(source);
}
@Override
public NoticeAddress[] newArray(int size) {
return new NoticeAddress[size];
}
};
}
activity1__activity2__activity1
</pre><pre name="code" class="java"><span style="white-space:pre"> </span> ArrayList<NoticeAddress> lis = classAdapter.getList();
NoticeAddress[] array = new NoticeAddress[lis.size()];
lis.toArray(array);
Intent intent = new Intent();
intent.putExtra("sendList", array);
setResult(RESULT_OK, intent);
finish();
<pre name="code" class="html">protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==REQUEST_CODE) {
if (resultCode == RESULT_OK) {
Parcelable[] receivedList = data.getParcelableArrayExtra("sendList");
for (int i = 0; i < receivedList.length; i++) {
System.out.println("~~~~~~[" + i + "]:" + ((NoticeAddress) receivedList[i]).getGroupName());
}
}
}
}
</pre>