Pass a mutableList from activity A to activity B in Kotlin.

南楼画角 提交于 2020-05-14 23:59:36

问题


I'm trying to pass data from activity A to activity B through intent in Kotlin.

The problem is I have a videos: MutableList<Video> and the intent.putParcelableArrayListExtra("VIDEOS", videos) only accepts ArrayList<out Parcelable> as arguments.

Questions

*. How do I send a mutableList data from activity A to activity B?

*. Or Do I have to convert it to ArrayList<Video> ?

PS: Videoimplements Parcelable


回答1:


Converting it to an ArrayList (or storing it as one in the first place?) is the easy solution if you want to stick to passing it through an Intent. There's an ArrayList constructor that takes a collection as its parameter:

intent.putParcelableArrayListExtra("VIDEOS", ArrayList(videos))


来源:https://stackoverflow.com/questions/48541446/pass-a-mutablelist-from-activity-a-to-activity-b-in-kotlin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!