Java Android:getParcelable返回空值?
作为我最后一个问题的后续内容: 我现在正试图通过Parcelable传递我的ArrayList。但是,当从其他活动获取时,它返回null。我似乎不明白为什么。我有以下几点 ResultsList.javaJava Android:getParcelable返回空值?,java,android,parcelable,Java,Android,Parcelable,作为我最后一个问题的后续内容: 我现在正试图通过Parcelable传递我的ArrayList。但是,当从其他活动获取时,它返回null。我似乎不明白为什么。我有以下几点 ResultsList.java public class ResultsList extends ArrayList<SearchList> implements Parcelable { /** * */ private static final long serialVersionUID =
public class ResultsList extends ArrayList<SearchList> implements Parcelable {
/**
*
*/
private static final long serialVersionUID = -78190146280643L;
public ResultsList(){
}
public ResultsList(Parcel in){
readFromParcel(in);
}
@SuppressWarnings({ "rawtypes" })
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public ResultsList createFromParcel(Parcel in) {
return new ResultsList(in);
}
public Object[] newArray(int arg0) {
return null;
}
};
private void readFromParcel(Parcel in) {
this.clear();
//First we have to read the list size
int size = in.readInt();
//Reading remember that we wrote first the Name and later the Phone Number.
//Order is fundamental
for (int i = 0; i < size; i++) {
String title = in.readString();
String Des = in.readString();
String message = in.readString();
SearchList c = new SearchList(title,Des,link);
this.add(c);
}
}
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
int size = this.size();
//We have to write the list size, we need him recreating the list
dest.writeInt(size);
//We decided arbitrarily to write first the Name and later the Phone Number.
for (int i = 0; i < size; i++) {
SearchList c = this.get(i);
dest.writeString(c.gettitle());
dest.writeString(c.getDescription());
dest.writeString(c.getmessage());
}
}
}
listOfResults
声明为resultslistofResults=newresultslist()代码>并在前面的代码中填充,然后将其与
Intent intent = new Intent(this ,newthing.class);
Bundle b = new Bundle();
b.putParcelable("results", listOfResults);
startActivityForResult(intent,0);
接收
Bundle extras = getIntent().getExtras();
ResultsList results = extras.getParcelable("results");
我想指出的是,我正在通过检查进入捆绑包的Arraylist的size(),然后检查出来,来测试这个空值。它可以很好地输入,但输出为空。未将捆绑包附加到intent!(doh!)被IRC上一位善良的绅士指出#安卓开发
Bundle extras = getIntent().getExtras();
ResultsList results = extras.getParcelable("results");