我想传递一个多维数组到一个活动
多维数组: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);
并且在另一个类(linechart类)中接收它,我使用:
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());
}
我得到以下错误:
Type mismatch: cannot convert from Serializable to double[][][]
有人能解释一下怎么做吗?
假设你有AActivity和BActivity
在AActivity中,声明变量和以下方法:
private static double[][][] doubleVar;
public static boolean[][][] getDoubleVar()
{
return doubleVar;
}
现在将值赋给AActivity中的doublear。
现在从BActivity中,你可以像这样访问doublear: aactivity . getdoublear ()
您必须将其强制转换为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());
}