In my application I am trying to pass ArrayList from one activity to another activity. how can I do that. please help! any sample.
Asked
Active
Viewed 422 times
1
-
1I don't agree that it's a duplicate. – Chris Horner Jan 17 '18 at 22:18
1 Answers
2
There's no method to pass an ArrayList<Float> as an extra, but you can pass a float[]. When creating the Intent to start your second Activity you'll need to convert your ArrayList<Float>.
float[] array = new float[arrayList.size()];
for (int i = 0; i < arrayList.size(); i++) {
array[i] = arrayList.get(i);
}
Then when you're starting your next Activity
Intent intent = new Intent(this, NextActivity.class);
intent.putExtra("floatArray", array);
In NextActivity, your float[] will be available in the extras. You can obtain it by calling
getIntent().getExtras().getFloatArray("floatArray");
Chris Horner
- 1,994
- 2
- 16
- 26