Reputation: 117
I want to pass a multidimensional array to an activity
multidimensional array:
double[][][] speed = new double[][][]
{
{
{ 15, 10 },
{ 16, 12 }
},
{
{ 14, 50 },
{ 18, 51 }
}
};
Bundle mBundle = new Bundle();
mBundle.putSerializable("speed", speed);
Intent myIntent = new Intent(getActivity(), LineChart.class);
myIntent.putExtra("speed", mBundle);
startActivity(myIntent);
And to receive it in another class (linechart class) i use:
private double[][][] _speed;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get ALL the data!!!
Bundle extras = getIntent().getExtras();
if (extras != null) {
this._speed = extras.getSerializable("speed");
}
setContentView(showLineChart());
}
I get the following error:
Type mismatch: cannot convert from Serializable to double[][][]
Can someone explain how to do this?
Upvotes: 0
Views: 1007
Reputation: 5076
Suppose you AActivity and BActivity
In AActivity, declare variable and the following method:
private static double[][][] doubleVar;
public static boolean[][][] getDoubleVar()
{
return doubleVar;
}
Now assign the value to to doubleVar in AActivity.
Now from BActivity, you can access doubleVar like this: AActivity.getDoubleVar()
Upvotes: 2
Reputation: 1036
You would have to cast it to double[][][]
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get ALL the data!!!
Bundle extras = getIntent().getExtras();
if (extras != null) {
this._speed = (double[][][]) extras.getSerializable("speed");
}
setContentView(showLineChart());
}
Upvotes: 0