简体   繁体   中英

(Android) Passing multidimensional array through intent

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?

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()

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());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM