I'm trying to pass a list of images to another activity
via a Parcelable
object in Android. I can convert the images down to a byte[] array
fine.
However, I've got a list of these images so there's going to be more than one byte[] array
.
Here is my code so far.
public class InvalidItem implements Parcelable {
public String id;
public ArrayList<byte[]> imageList = new ArrayList<>();
public InvalidItem(String id) {
this.id = id;
}
public InvalidItem(Parcel in) {
String[] data = new String[22];
in.readStringArray(data);
this.id= data[0];
this.imageList = data[1];
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeStringArray(new String[]{
this.id,
String.valueOf(this.imageList)
});
}
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public InvalidItem createFromParcel(Parcel in) {
return new InvalidItem(in);
}
public InvalidItem[] newArray(int size) {
return new InvalidItem[size];
}
};
}
As you can see I write the string array which would work for one byte[] array
. Is there a way I could have a list of byte[] arrays
that I decode into one string and then encode when I want to show the images?
I've tried looking into solutions and people have suggested passing it in the bundle.
However, this application follows a step by step process and requires an object to store the data in.