0

I have this ArrayList

private ArrayList<ArrayList<MyCustomObject>>schedule;

So each element of this array is another array list of my custom object

How would I go about writing this to parcel?

This is my initial approach but wondering if there is a clean and shorter way.

Writing to parcel

if(schedule != null){
        dest.writeInt(schedule.size());
        for (ArrayList<MyCustomObject> schedules : schedule) {
            dest.writeTypedList(schedules);
        }
    }

Reading from parcel

int sizeOfSchedule = in.readInt();
        schedule = new ArrayList<>();
        for(int i = 0; i < sizeOfSchedule; i++){
            schedule.add(in.createTypedArrayList(MyCustomObject.CREATOR));
        }

UPDATED 1 : Tested the above and it works

Ersen Osman
  • 7,067
  • 8
  • 47
  • 80
  • So what's the endpoint/product that you want to reach? – DarkV1 May 04 '16 at 14:34
  • @DarkV1 What i posted works but look how much code it is. I want to see if there is shorter way, maybe it exists in the framework already but I could not find any examples of writing an array of array of objects to parcel – Ersen Osman May 04 '16 at 14:36

0 Answers0