I have a custom class filled with information of a User. I use an ArrayList to hold all the User class data. I would like to pass the array to another activity where the it can be read and modified. Since the array could be large, I need this process to be done as efficiently and fast as possible, which is why I choose to use Parcelable instead of Serializable.
I am having trouble doing this using Kotlin. There are lots of Java tutorials but none are in Kotlin, which is what makes this question different then all the others. Can someone please provide and explain the code in Kotlin on how this can be achieved?
This is what I have so far:
constructor(`in`:Parcel) {
CollegeName = `in`.readString()
override fun describeContents(): Int {
return 0
override fun writeToParcel(dest: Parcel?, flags: Int) {
private fun readFromParcel(`in`:Parcel) {
CollegeName = `in`.readString()
companion object {
@JvmField final val CREATOR: Parcelable.Creator<College> = object: Parcelable.Creator<College> {
override fun createFromParcel(source: Parcel): College {
return College(source)
override fun newArray(size: Int): Array<College?> {
return arrayOfNulls<College>(size)
class Series() : Parcelable {
private var name: String? = null
private var numOfSeason: Int = 0
private var numOfEpisode: Int = 0
constructor(parcel: Parcel) : this() {
val data = arrayOfNulls<String>(3)
parcel.readStringArray(data)
this.name = data[0]
this.numOfSeason = Integer.parseInt(data[1])
this.numOfEpisode = Integer.parseInt(data[2])
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(name);
parcel.writeInt(numOfSeason);
parcel.writeInt(numOfEpisode);
private fun readFromParcel(parcel: Parcel){
name = parcel.readString()
numOfSeason = parcel.readInt()
numOfEpisode = parcel.readInt()
override fun describeContents(): Int {
return 0
companion object CREATOR : Creator<Series> {
override fun createFromParcel(parcel: Parcel): Series {
return Series(parcel)
override fun newArray(size: Int): Array<Series?> {
return arrayOfNulls(size)
and then in your Activity
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
val i = Intent(this, SecondActivity::class.java)
val testing = ArrayList<testparcel>()
i.putParcelableArrayListExtra("extraextra", testing)
startActivity(i)
class SecondActivity :Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.secondActivty_activity)
val testing = this.intent.getParcelableArrayListExtra<Parcelable>("extraextra")