1

I have parcelable class Category

public static class Category implements Parcelable {
    public String name;
    public int id;
    public ArrayList<Category> childrenCategory;

    public Category(Parcel in) {
        super();
        readFromParcel(in);
    }

    public static final Parcelable.Creator<Category> CREATOR = new Parcelable.Creator<Category>() {
        public Category createFromParcel(Parcel in) {
            return new Category(in);
        }

        public Category[] newArray(int size) {
            return new Category[size];
        }

    };

    public void readFromParcel(Parcel in) {
        this.name = in.readString();
        this.id = in.readInt();
    }

    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(name);
        dest.writeInt(id);
    }

    @Override
    public int describeContents() {
        return 0;
    }
}

and I want to pass it with Intent in this way

public void onClick(View v) {
            ArrayList<Categories> categories = new ArrayList<Categories>();
            Intent intent = new Intent(getApplicationContext(),
                    MainActivity.class);

            Bundle bundle = new Bundle();
            bundle.putParcelableArrayList("arrayListName", categories);
            inten.putExtra("bundleName", bundle);
            startActivity(intent);
        }

and read it with this code

Intent intent = getIntent();
Bundle bundle = intent.getExtras();
ArrayList<Category> categories = b.getParcelableArrayList("arrayListName");

I am missing code from readFromParcel and writeToParcel methods.

Can anyone suggest something.

pepela
  • 423
  • 5
  • 17
  • why don't you simply call writeToParcel on each child ? – njzk2 Feb 11 '13 at 10:22
  • If you are just trying to pass this from one activity to another, I would just store it in a `public static` member variable of a singleton class. That is way easier and you won't be creating tons of objects. – David Wasser Feb 11 '13 at 10:26

0 Answers0