0

I'm trying to send MutableList<Point> array list as Extra from Intent to another in kotlin. Declaring the list:

private var thePoints: MutableList<Point> = mutableListOf()

and here is how I add items to it:

                if (startStationPoint != null) {
                    thePoints.add(startStationPoint)
                }

And am using this method to send it to the other Activity:

            navigationActivity.putParcelableArrayListExtra(
                "thePoints",
                thePoints)

It gives me this error:

Type mismatch:
Required: ArrayList<out Parcelable>!
Found: MutableListM<Point>

as am using putParcelableArrayListExtra as there is no such thing to put points arraylist extra.

Ahmed Wagdi
  • 3,913
  • 10
  • 50
  • 116

2 Answers2

1

The error explains you are using as argument a mutable list but you have to use an array

thePoints.toList().toTypedArray()

I'm not sure if that will work because Point can not meet the conditions

You could create a class representing the point

data class SerializablePoint(val longitude: Long, val latitude: Long) : Serializable

And then use .map to convert them.

Or you could do the same with parceleable.

Another options is to try Pair which is Kt API, but again I don't know if parcealability or serializability conditions are complied.

To figure it out ctrl+click on any of those classes and see if in any point implements serializable or parceleable, otherwise transforming to a custom class will be needed.

cutiko
  • 9,887
  • 3
  • 45
  • 59
0

you can use Google Gson to convert the object to a string and then pass it as a string. from the receiving end convert the string to your original object.

Refer this ->

https://stackoverflow.com/a/33381385/9901309

RAINA
  • 802
  • 11
  • 22