I'm using Kotlin with Anko and I want to send to another activity a list of Players.
class Player(var name: String?) {
var score: Int = 0
init {
this.score = 0
}
}
My activity:
class MainActivity: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle ? ) {
btn.setOnClickListener {
val players = ArrayList <Player> ()
players.add(Player("John"))
players.add(Player("Jeff"))
startActivity <ScoreActivity> ("key" to players)
}
}
}
When the code reaches the startActivity line, I get this error:
java.lang.RuntimeException: Parcel: unable to marshal value com.yasin.myapp.Player@4e3940e
I suppose something is wrong with my class Player, but I don't know what. I'm using kotlin version 1.1.4. Someone can help me?