0

realm database use findfirst() method send the data in mBundle.putSerializable("data", (Serializable) item); the item data value able receive next activity its show java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = io.realm.StationAndLocationModelRealmProxy)

DGAD
  • 35
  • 5

1 Answers1

1

You need to make your object parcelable, not serializable.

public class Channel extends RealmObject implements Parcelable {

    private String channelName;
    private String channelUrl;
    private String channelImg;
    private String channelGroup;

    public Channel() {
    }

    public String getChannelName() {
        return channelName;
    }

    public void setChannelName(String channelName) {
        this.channelName = channelName;
    }

    public String getChannelUrl() {
        return channelUrl;
    }

    public void setChannelUrl(String channelUrl) {
        this.channelUrl = channelUrl;
    }

    public String getChannelImg() {
        return channelImg;
    }

    public void setChannelImg(String channelImg) {
        this.channelImg = channelImg;
    }

    public String getChannelGroup() {
        return channelGroup;
    }

    public void setChannelGroup(String channelGroup) {
        this.channelGroup = channelGroup;
    }

    @NonNull
    @Override
    public String toString() {
        return "Channel{" +
                ", channelName='" + channelName + '\'' +
                ", channelUrl='" + channelUrl + '\'' +
                ", channelImg='" + channelImg + '\'' +
                ", channelGroup='" + channelGroup + '\'' +
                '}';
    }

    public Channel(Parcel in) {
        String[] data = new String[4];
        in.readStringArray(data);
        this.channelName = data[0];
        this.channelUrl = data[1];
        this.channelImg = data[2];
        this.channelGroup = data[3];
    }

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

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeStringArray(new String[]{this.channelName, this.channelUrl, this.channelImg, this.channelGroup});
    }

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

        @Override
        public Channel[] newArray(int i) {
            return new Channel[i];
        }
    };
}
BroscR
  • 167
  • 2
  • 11
  • Here send the Bundle data use putSerializable method like - **mBundle.putSerializable("data", (Serializable) item);** intent not able pass the data to the next activity show logcat Title warning – DGAD Oct 17 '21 at 04:04
  • Yes, it is normal that it gives this because realm objects need to be parcelable, not serializable. [Parcelable](https://stackoverflow.com/questions/10107442/android-how-to-pass-parcelable-object-to-intent-and-use-getparcelable-method-of) First make the realm object class as parcelable as above and then you can do things like in this link while moving the object with intent. – BroscR Oct 17 '21 at 06:51