I need to pass a Double ArrayList between activities in an Android application using a Bundle. I noticed that there is a method bundle.putIntegerArrayList(), but I cannot find a corresponding method for Double ArrayList.
Here’s a sample code snippet that illustrates the problem:
ArrayList<Double> doubleArrayList = new ArrayList<>();
doubleArrayList.add(1.0);
doubleArrayList.add(2.0);
doubleArrayList.add(3.0);
Bundle bundle = new Bundle();
bundle.putDoubleArrayList("key", doubleArrayList); // This method doesn't exist
Problem:
The Bundle class does not have a putDoubleArrayList() method, and I am unsure how to pass a Double ArrayList using a Bundle.
Question:
How can I pass a Double ArrayList in a Bundle? What is the correct method or approach to achieve this?
What I've Tried:
Looking for Alternative Methods: I checked the documentation and found that Bundle supports putIntegerArrayList(), putStringArrayList(), but there is no putDoubleArrayList() method.
Converting to Primitive Arrays: I considered converting the Double ArrayList to a primitive double[] array before putting it in the Bundle.
Why you need use bundle. you can just put it in Intent directly. And because Array list implement Serializable you won't have any problems.
intent.putExtra("array", doubleArray);
If you need use Bundle then
bundle.putSerializable("array", doubleArray);