0

How to send an 2D array of parcelable object into another activity through intent? Any help?

Here is my Parcelable custom Object:

public class PTagData implements Parcelable {
    public int mStartWordIndex;

    public PTagData(int startWordIndex) {
        this.mWordsPerRow = wordsPerRow;
    }

    protected PTagData(Parcel in) {
        mStartWordIndex = in.readInt();
    }
    public static final Creator<PTagData> CREATOR = new Creator<PTagData>() {
        @Override
        public PTagData createFromParcel(Parcel in) {
            return new PTagData(in);
        }

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

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

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(mStartWordIndex);
    }
}

I than create an object like that :

final PTagData[][] datas = new PTagDatas[2][30];

for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 30; j++) {
        datas[i, j] = getTagDatas(i, j);
    }
}

How to pass such object to another activity ?

hamid
  • 97
  • 1
  • 9
  • 1
    as a workaround, you might create a class `SomeClass`, which will implement parcellable, and contain the 1D array of your object, then you create another 1D array of `SomeClass`, and pass it as 1D array of Parcellable. Or also you may join your 2D array into 1D array, and then split it back to 2D – Vladyslav Matviienko Mar 07 '19 at 08:07
  • Second solution seems better. – hamid Mar 07 '19 at 08:18
  • that's all up to you. There is no standard way to do that, you can choose any workaround you wnt. – Vladyslav Matviienko Mar 07 '19 at 08:50

0 Answers0