我有我使用從一個CSV文件(稱爲CSVReader)解析數據類,裏面有用於解析一些方法,以及一對夫婦的字符串和一個自定義對象類型的列表(List allRecords)。 我正在做的是當應用程序加載時,將所有數據解析到該列表中,然後嘗試將該信息傳遞給下一個活動,但在下一個活動中,我將所有記錄保留爲空。從一個Android的活動傳遞對象到另一個
LoginActivity
CSVReader data = new CSVReader();
data.populateRecords(this);
Intent intent = new Intent(LoginActivity.this, Find.class);
Bundle bundle = new Bundle();
bundle.putParcelable("list", data);
intent.putExtra("bundle", bundle);
startActivity(intent);
我已經通過了調試和包在裏面絕對有數據。
查找
Intent intent = getIntent();
Bundle bundle = intent.getBundleExtra("bundle");
data = (CSVReader) bundle.getParcelable("list");
使用調試器仍然和mmap(中包)現在是零,所以是數據。
我做錯了什麼? DummyData和CSVReader都實現了Parcelable。
編輯:添加自定義類CSVReader:
List<DummyData> allRecords;
private String base;
private String location;
private String partner;
public static Creator<CSVReader> CREATOR = new Creator<CSVReader>(){
@Override
public CSVReader createFromParcel(Parcel source){
return new CSVReader(source);
}
@Override
public CSVReader[] newArray(int size) {
return new CSVReader[size];
}
};
private CSVReader(Parcel in){
allRecords = new ArrayList<DummyData>();
in.readTypedList(allRecords, DummyData.CREATOR);
base = in.readString();
location = in.readString();
partner = in.readString();
}
...
...
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(base);
dest.writeString(location);
dest.writeString(partner);
dest.writeList(allRecords);
}
而不是'bundle.getParcelable(「this」);'它應該是'bundle.getParcelable(「list」);' –
@DanielZolnai你是對的,但是這並沒有解決它 – John
請張貼你的自定義對象類,您正在嘗試傳遞給下一個活動的類。 –