I am trying to pass array of customized object using Parcelable. I found some discussions in my search like link. I followed these examples and but can't find the implementation for the array of objects. My problem is object becomes null at the new activity. My implementation is as follow.
MY percelable object
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);
At the new activity, I extract as
Bundle bundle = getIntent().getExtras();
showStatObjinDisplay = (showStatisticsObj) bundle.getParcelable("bundleObj");
But showStatObjinDisplay is null. What is wrong?Pls help me.