Android: getParcelable возвращает ноль?

1

Как следует из моего последнего вопроса: Передача Arraylist между действиями? Использование Parcelable

Теперь я пытаюсь передать свой ArrayList через Parcelable. Однако, когда он получил от другого действия, он возвращает 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");

Я хотел бы указать, что я тестирую эту нулевую вещь, проверяя размер() Arraylist, входящего в Bundle, и затем он выходит. Он идет нормально и выходит нулевым.

Теги:
parcelable

1 ответ

0

Не привязывал пучок к намерениям! (doh!) был отмечен добрым джентльменом на IRC! # android-dev

Ещё вопросы

Сообщество Overcoder
Наверх
Меню