Parcelable implementation with ArrayList<custom-object>
android, android-intent, java, parcelable
Solution
The `putExtra()` and `getSerializable()` methods will store and retrieve an `ArrayList<?>` of your custom objects, with no interface implementing required. (Your custom object class should implement `Serializable` interface though).
But in your case, you can simply use `putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value)` and `getParcelableArrayListExtra(String name)`.
Problem
I think it's just a stupid mistake but the `ArrayList` always ends up `null`. It's driving me crazy so thought I'd ask for help. Object class: ``` import android.os.Parcel; import android.os.Parcelable; public class StoryTag implements Parcelable { private String tagTitle; private int occurrence; public StoryTag() { } public StoryTag(Parcel in) { tagTitle = in.readString(); occurrence = in.readInt(); } public String getTagTitle() { return tagTitle; } public void setTagTitle(String tagstring) { this.tagTitle = tagstring; } public int getOccurrence() { return occurrence; } public void setOccurrence(int occurrence) { this.occurrence = occurrence; } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(tagTitle); dest.writeInt(occurrence); } public int describeContents() { return 0; } public static final Parcelable.Creator<StoryTag> CREATOR = new Parcelable.Creator<StoryTag>() { public StoryTag createFromParcel(Parcel in) { return new StoryTag(in); } public StoryTag[] newArray(int size) { return new StoryTag[size]; } }; } ``` `MainActivity`: ``` Intent tagIntent=new Intent(this,DisplayTagList.class); tagIntent.putExtra("taglist", taglist); startActivity(tagIntent); return true; ``` Receiving activity: ``` Bundle storyTagBundle = getIntent().getExtras(); ArrayList<StoryTag> listoftags = storyTagBundle.getParcelable("taglist"); ``` Thanks a ton for any help you can offer. Pulling my hair out here for what I think is a minor error.