Android:getParcelable返回null?

时间:2011-04-12 16:59:38

标签: java android parcelable

从我上一期的问题开始:Passing Arraylist between activities? Using Parcelable

我现在正试图通过Parcelable传递我的ArrayList。但是,当它从其他活动中获取时,它返回null。我似乎无法弄清楚为什么。我有以下内容......

ResultsList.java

 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());
    }
}
 }

SearchList.java

 public class SearchList {
private String title;
  private String description;
  private String message;
  public SearchList(String name, String phone, String mail) {
          super();
          this.title = name;
          this.description = phone;
          this.message = mail;
  }
  public String gettitle() {
          return title;
  }
  public void setTitle(String title) {
          this.title = title;
  }
  public String getDescription() {
          return description;
  }
  public void setDescription(String description) {
          this.description = description;
  }
  public String getmessage() {
          return message;
  }
  public void setmessage(String link) {
          this.message = message;
  }
 }

listOfResults被声明为ResultsList listOfResults = new ResultsList();并在代码的前面填充它随后发送...

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");

我想指出我正在通过检查进入Bundle的Arraylist的size()然后它出来来测试这个null的东西。它很好,并且无效。

1 个答案:

答案 0 :(得分:0)

没有附加捆绑意图! (doh!)在IRC上被一位善良的绅士指出! #android-dev