Question

I've a class that is Parcelable and has some fields. One of those fields is a MarkerOptions, and I'm trying to find out how I can read and write those MarkerOptions...

I know the MarkerOptions class is Parcelable, but I have no clue on how to read and write it from another class...

Let's say I have this class:.

public class Foo implements Parcelable {
    private MarkerOptions markerOptions;
    private String someField; 

    public Foo() {}

    public Foo(Parcel in) {
        this.markerOptions = in.readParcelable(MarkerOptions.class.getClassLoader());
        this.someField= in.readString();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(markerOptions, flags);
        dest.writeString(someField);    
    }

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

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

How can I read and write the MarkerOptions?

Was it helpful?

Solution

To write a Parcelable to a Parcel, call writeParcelable(). To read a Parcelable from a Parcel, call readParcelable().

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