我正在尝试使用 Parcelable 传递自定义对象的数组。我在搜索中发现了一些讨论,例如链接。我遵循了这些示例,但找不到对象数组的实现。我的问题是对象在新活动中变为空。我的实现如下。
我的可感知对象
public class showStatisticsObj implements Parcelable{
public String dt = null;
public int totalmiles = 0;
public Date date = null;
public showStatisticsObj() { ; };
public showStatisticsObj(Parcel in) { readFromParcel(in); }
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel arg0, int arg1) {
// TODO Auto-generated method stub
arg0.writeString(dt);
arg0.writeInt(totalmiles);
}
public void readFromParcel(Parcel in) {
dt = in.readString();
totalmiles = in.readInt();
}
@SuppressWarnings("rawtypes")
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public showStatisticsObj createFromParcel(Parcel in)
{
return new showStatisticsObj(in);
}
public showStatisticsObj[] newArray(int size)
{
return new showStatisticsObj[size];
}
};
}
Parcelable[] passedArray = new Parcelable[totaldifferentDates];
for (int i=0; i<totaldifferentDates; ++i) {
passedArray[i] = showStatObj[i];
}
Intent displayintent = new Intent(this, DisplayStatistics.class);
displayintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
displayintent.putExtra("bundleObj", passedArray);
startActivity(displayintent);
在新活动中,我提取为
Bundle bundle = getIntent().getExtras();
showStatObjinDisplay = (showStatisticsObj) bundle.getParcelable("bundleObj");
但 showStatObjinDisplay 为空。怎么了?请帮帮我。