0

I must deliver an Object value to other Activity, so I found the way to using Parcelable Object. but this is the problem

the outer ParcelableOjbect (I'll call this "1") has inner ParcelableOjbect variable(I'll call this "2"). so what I have to do is add innerParcelableObject into a outerParcelableObject.

the "2" which is I'll add is already setted up to Parcelable class

but the error occured line says this

writeParcelable(Parcelable, int) in Parcel cannot be applied
to             (State)

This is the (1)

ublic class Progress implements Parcelable {
    String time;
    String location;
    State status;                  // <<<----- this is (2)
    String description;

    public Progress(){}
    public Progress(String time, String location, State status, String description) {
        this.time = time;
        this.location = location;
        this.status = status;
        this.description = description;
    }
    protected Progress(Parcel in){
        in.writeString(time);
        in.writeString(location);
        in.writeParcelable(status);   // <<--  the error occured here
        in.writeString(description);
    }

    public static final Creator<Progress> CREATOR = new Creator<Progress>() {
        @Override
        public Progress createFromParcel(Parcel in) {
            return new Progress(in);
        }

        @Override
        public Progress[] newArray(int size) {
            return new Progress[size];
        }
    };

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

    @Override
    public void writeToParcel(Parcel dest, int flags) {

    }

    // ... getters and setters

}

This is the (2)

public class State implements Parcelable {

    String id;
    String text;

    public State(String id, String text) {
        this.id = id;
        this.text = text;
    }
    protected State(Parcel in) {
        in.writeString(id);
        in.writeString(text);
    }

    public static final Creator<State> CREATOR = new Creator<State>() {
        @Override
        public State createFromParcel(Parcel in) {
            return new State(in);
        }

        @Override
        public State[] newArray(int size) {
            return new State[size];
        }
    };

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

    @Override
    public void writeToParcel(Parcel dest, int flags) {

    }

    // ... getters and setters
}

Is anything missing on this?

Jin-guk Park
  • 221
  • 1
  • 3
  • 12

1 Answers1

0

I solved this problem myself

The following link says the way to add ParcelableObject into ParcelableObject. thanks to this link https://guides.codepath.com/android/using-parcelable

This is content the method named "writeToParcel"

        out.writeString(title);
        out.writeParcelable(from, flags);

as you can see, when you add Parcelable Object, you have to pass "flags" for argument.

Then, when you read from Parcel

        title= in.readString();
        from = in.readParcelable(Person.class.getClassLoader());

You can read from parcel to use this way. And attention! You must matching their index that you wrote.

I hope this solution will help others

Jin-guk Park
  • 221
  • 1
  • 3
  • 12