简体   繁体   中英

Pass multidimensional ArrayList of LatLng through intent

I am trying to pass an ArrayList<ArrayList<LatLng>> from one intent to another using putParcelableArrayListExtra () but for some reason it doesn't like my list. I define the array list with ArrayList<ArrayList<LatLng>> listOfStrokes = new ArrayList<>(); and I am trying to pass it with

ArrayList<ArrayList<LatLng>> listOfStrokes = new ArrayList<>();

Intent intent = new Intent(this, CreateFarm.class);

intent.putParcelableArrayListExtra("listOfStrokes", listOfStrokes);

but I am getting a

Error:(383, 65) error: incompatible types: ArrayList> cannot be converted to ArrayList

error. Is there a way to pass this object?

First - consider using Guava tables to avoid a List of Lists pattern.

putParcelableArrayListExtra expects a List of objects that implements Parcelable. ArrayList does not. Arraylist implements Serializable, so the below will work.

ArrayList<ArrayList<LatLng>> listOfStrokes = new ArrayList<>();

Intent intent = new Intent(this, CreateFarm.class);

intent.putExtra("listOfStrokes", listOfStrokes);

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