Pass mutableList through intent

Viewed 1058

I have a mutableList.

var newList: MutableList<String> = mutableListOf()

How to pass newList through intent?

I tried this but not working.

 mIntent.putParcelableArrayListExtra("mFilePath", ArrayList(newList))

Error

Type inference failed. Expected type mismatch: required: java.util.ArrayList! found: kotlin.collections.ArrayList /* = java.util.ArrayList */

3 Answers

Was able to fix it.

  mIntent.putStringArrayListExtra("mFilePath", ArrayList(newList))

You can use this way

intent.putParcelableArrayListExtra("NEW_LIST", ArrayList(newList))

you can convert it on arraylist and pass as putParcelableArrayListExtra through intent

you can create separate model class and add that model class to your arraylist and make it Parcelize through this you can achieve this@Parcelize class model:Parcelable{ }

Related