0

The question has been asked here Pass multidimensional ArrayList of LatLng through intent but it does not have an actual answer.

I have done what the answer there states, and I can pass it through without error,

intent.putExtra("lat_lng_list", mLatLonList);

but I am unable to receive it on the other end. The closest I have come was using:

final ArrayList<ArrayList<LatLng>> latLngList = intent.getParcelableExtra("lat_lng_list");

but this just returns null, even though it's not. I know LatLng implements parcelable, I was able to pass an ArrayList of LatLng using the same .putExtra and retrieving it with intent.getParcelableArrayListExtra(), but that won't work for the multidimensional one either. Anything helps.

Tommy Jackson
  • 609
  • 7
  • 20
  • 1
    https://stackoverflow.com/questions/42417241/passing-an-arraylistobject-from-one-intent-to-another – sdfbhg Oct 25 '17 at 17:01

1 Answers1

3

An ArrayList does not implements Parcelable, but it implements Serializable. You can't use getParcelableExtra to receive the data, you must use getSerializableExtra instead. Like this:

final ArrayList<ArrayList<LatLng>> latLngList = (ArrayList<ArrayList<LatLng>>) intent.getSerializableExtra("lat_lng_list");

You can also use intent.putParcelableArrayListExtra() and intent.getParcelableArrayListExtra() if you use large ArrayList's. Also make sure that LatLng implements Serializable.

Reference:

https://stackoverflow.com/a/28733592/5457878

gi097
  • 7,313
  • 3
  • 27
  • 49