I have this collection
ArrayList<int[]>[] myList;
that is, an array of ArrayLists of integer arrays. I am trying to pass it in an intent.
intent.putExtra(getString(R.string.app_name) + ".myList", myList);
In the new activity I try to get the extra as:
ArrayList<int[]>[] myList;
Intent intent = getIntent();
myList = (ArrayList<int[]>[]) intent.getSerializableExtra(getString(R.string.app_name) + ".myList");
However I am getting a class cast exception in that line.
Caused by: java.lang.ClassCastException: java.lang.Object[] cannot be cast to java.util.ArrayList[]
As they contain arrays of primitive types and ArrayList is a serializable class itself, I am at a loss as to why this isn't working or what would be a better way to proceed.
EDIT
It appears that one can't just cast Object[] to CustomClass[]
Check:
Quick Java question: Casting an array of Objects into an array of my intended class
casting Object array to Integer array error
So one solution would be
Object[] tmp = (Object[]) intent.getSerializableExtra(getString(R.string.app_name) + ".myList");
myList = Arrays.copyOf(tmp, tmp.length, ArrayList[].class);
Or alternatively, one can pass and retrieve an ArrayList
// Calling Activity
ArrayList<ArrayList<int[]>> myIntentList = new ArrayList(Arrays.asList(myList));
intent.putExtra(getString(R.string.app_name) + ".myList", myIntentList);
// Called Activity
ArrayList<ArrayList<int[]>> myIntentList;
myIntentList = ArrayList<ArrayList<int[]>> intent.getSerializableExtra(getString(R.string.app_name) + ".myList");