The Intent class internally uses a Bundle to save the values passed to putExtra()
method.
The class provides several versions (overloading) of the putExtra()
method, including one that receives a serializable , as is the case for any type of Array .
When using
int[][] meuArray= new int[5][3];
...
...
intent.putExtras("meuArray", meuArray);
The overloaded method used is putExtra (String name, Serializable value) .
So, to retrieve the original array, you must use the method getSerializableExtra (String name) and not getIntArrayExtra (String name ) :
String[][] meuArray = (int[][])getIntent().getSerializableExtra("meuArray");
Note: It seems like a bug a> on Android 4 the error is thrown
java.lang.ClassCastException: java.lang.Object [] can not be cast to int [] []
When doing cast return method to int[][]
.
If this is the case, use
Object[] vector;
int[][] meuArray;
vector = (Object[])getIntent().getSerializableExtra("meuArray");
meuArray = Arrays.copyOf(vector, vector.length, int[][].class);
to retrieve the array.