Dan Brian Arenas Dan Brian Arenas - 2 months ago 7
Android Question

Passing bidimensional String Array variable from 1 activity to another

I have a bidimensional String array that has mass data (sizes are

[40][8]
to be exact) in my Activity A. I want to pass the whole array to Activity B. I've tried this solution: Passing string array between android activities

but the problem is it is creating an array inside. I want to pass my original bidimensional array that contains
[40][8]
values. Can I do that?

EDIT:

my String array is a 2 dimensional array.

Answer

Since your array is bidimensional and bidimensional array are serializable, you can use a bundle:

Intent intent = new Intent(this, activityB.class);
Bundle bundle = new Bundle();
bundle.putSerializable("myArray", myBidimensionalArray);
intent.putExtras(bundle);

and in activityB you can simply call:

Intent passed = getIntent();
Bundle bundle = passed.getExtras();
String[][] myPassedArray = (String[][]) bindle.getSerializable("myArray");

and you are done