0

How to pass the ArrayList of ArrayList , for example I have created one object.

For example,

I have a class OperationInfo and I need to pass ArrayList<ArrayList<OperationInfo>> to other class. my OperationInfo class is parcelable.

but it seems intent does not allow us to pass the list of a list using putParcelableArrayListExtra

is there a way to pass list of list to another class ?

Hunt
  • 8,215
  • 28
  • 116
  • 256

2 Answers2

0

I guess you can do it manually looping through list and saving each sublist into bundle while having key as index along with total count

Bundle data = new Bundle();
data.putInt("size", mainList.size);
int key = 0;
for(ArrayList<OperationInfo> operationInfoList: mainList){
    data.putParcelableArrayListExtra(""+ (key++), operationInfoList)
} 

Pass the above bundle and at receiving end

 ArrayList<ArrayList<OperationInfo>> decodedList = new ArrayList<>();
 int size = getIntent().getIntExtra("size", 0);
 for(int key = 0; key < size; key++){
    decodedList.add(getIntent().getParcelableArrayListExtra(""+(key--)));
 }
Rajan Kali
  • 12,627
  • 3
  • 25
  • 37
0

Simply use intent.putExtra() and pass your parceable arraylist.

And get arraylist like this in other activity

getIntent().getParcelableExtra("param_name");