Passing Number[] array through Intent

170 views Asked by At

i am struggling on passing an array from one activity to another. In my MainActivity i build an array similar to this:

Number[] s1 = {1, 8, 5, 2, 7, 4};

The reason i need it in that format, is to graph those points using androidplot in the other activity. Anyways, I send it in this manner:

Intent intent = new Intent(this, DataTable.class);
        intent.putExtra("plotpoints", s1);
        startActivity(intent);

In my other activity i try to extract my variable

Bundle extras = getIntent().getExtras();
Number[] series1Numbers = extras.getStringArray("plotpoints");

However this gives me an incompatible types error. I know that the problem is in this part of my code:

extras.getStringArray("plotpoints");

but the only functions available for getting arrays are:

getParcelableArray();
getIntegerArrayList();
getParcelableArrayList();
getStringArrayList();
getSparceParcelableArray();
getBooleanArray();
getByteArray();
getCharArray();
getFloatArray();
getShortArray();
getDoubleArray();
getIntArray();
getLongArray();
getStringArray();
getCharSequenceArray();
getCharSequenceArrayList();

I don't see something similar to a getNumberArray(); How am i able to get around this little problem? Appreciate it. :)

2

There are 2 answers

0
frogmanx On BEST ANSWER

The Number class implements Serializable. So you should be able to do the following:

Bundle extras = getIntent().getExtras();
Number[] series1Numbers = (Number[]) extras.getSerializable("plotpoints");
0
Mark On

Use:

int[] s1 = {1, 8, 5, 2, 7, 4};  

For your array and retrieve it using:

int[] series1Numbers = extras.getIntArray("plotpoints");

You have incomtpatiable types because you put a int array as an extra, not a string array.