2

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.

Aks4125
  • 4,522
  • 4
  • 32
  • 48
Connor Brady
  • 81
  • 2
  • 10
  • Check out: https://stackoverflow.com/questions/4352172/how-do-you-pass-images-bitmaps-between-android-activities-using-bundles – sshashank124 Feb 20 '18 at 09:12
  • what do you need `byte[]` for? what do you want to store there? how the other activity will use it? – pskink Feb 20 '18 at 09:13
  • @pskink The byte[] is image that has been taken and compressed into a byte[] array. One byte[] array would work fine for one image, however I have multiple and need a list of these byte[] passing through. The other activity will convert the array back into a Bitmap. – Connor Brady Feb 20 '18 at 09:38
  • how big is that byte[] (just for one image) - you know that the limit is 2M? (or even 1M - i dont remember...) - if your image is 1000x1000 for example it would be 4M so.... – pskink Feb 20 '18 at 09:39
  • Maybe [this](https://stackoverflow.com/questions/11519691/passing-image-from-one-activity-another-activity) would help you in your problem. – Tarek Mohamed Feb 20 '18 at 09:43
  • @pskink Ah right thank you for clarifying that. The images are somewhere around 6M so that's not going to work. – Connor Brady Feb 20 '18 at 09:44
  • 6M? forget it... – pskink Feb 20 '18 at 09:45
  • @pskink Woop. I may have an alternative solution from the link Tarek has provided. I'll post an update once done – Connor Brady Feb 20 '18 at 09:49

0 Answers0