Question

I have my class Video which implements Parcelable. I'm having problems on my constructor, and what is giving me problems is the variable mSource which is an ArrayList<URI>. I put an arrow on the line which is giving me problems.

public class Video implements Parcelable {
public URI mThumb;
public ArrayList<URI> mSource;
public String mTitle;
public String mSubTitle;
public String mDescription;

public Video(final URI thumb, final URI source, final String title, final String subtitle,
        final String description) {
    this.mThumb = thumb;
    this.mSource = new ArrayList<URI>(1);
    this.mSource.add(source);
    this.mTitle = title;
    this.mSubTitle = subtitle;
    this.mDescription = description;
}

public Bundle getAsBundle() {
    Bundle b = new Bundle();
    b.putString("title", mTitle);
    b.putString("subtitle", mSubTitle);
    b.putString("description", mDescription);
    b.putString("thumb", mThumb.toString());
    b.putString("source", mSource.get(0).toString());
    return b;
}

@Override
public int describeContents() {
    // TODO Auto-generated method stub
    return 0;
}


@Override
public void writeToParcel(Parcel out, int arg1) {
    // TODO Auto-generated method stub
    out.writeString(mTitle);
    out.writeString(mSubTitle);
    out.writeString(mDescription);
    out.writeString(mThumb.toString());
    out.writeString(mSource.get(0).toString());
}

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

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

    private Video(Parcel in) {
        mTitle = in.readString();
        mSubTitle = in.readString();
        mDescription = in.readString(); 
        mThumb = new URI(in.readString());
        mSource = new ArrayList<URI>();
        in.readTypedList(mSource, Video.CREATOR); //<----THIS LINE RIGHT HERE. 
    }

}

I have tried readList, readTypedList but I keep getting the error saying that it's not applicable for the arguments(..); Any suggestions?

Was it helpful?

Solution

out.writeString means you can't use in.readTypedList to read it back, you need to use in.readString()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top