Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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.
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.
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
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.