Parcelize Kotlin(org.jetbrains.kotlin.android.extensions)

时间:2018-04-13 07:14:31

标签: android kotlin kotlin-android-extensions

这是我的数据类,它使用Parcelable

扩展@Parcelize 和注释
@Parcelize
data class MusicTrack(
    val id: Long,
    val title: String,
    val albumId: String,
    val artist: String,
    val duration: String,
    val trackArt: String = "",
    val fileUri: Uri) : Parcelable

然后我尝试将其放入一个包中以发送

override fun playTrack(position: Int, musicList: ArrayList<MusicTrack>) {
    info { musicList }
    val bundle = Bundle()
    bundle.putParcelableArrayList(Config.MusicConfig.MUSIC_TRACKS, musicList)
    bundle.putInt(Config.MusicConfig.MUSIC_TRACK_POSITION, position)
    MediaControllerCompat.getMediaController(this).transportControls.playFromUri(Uri.parse("Hack"), bundle)
}

使用捆绑包

  override fun onPlayFromUri(uri: Uri?, extras: Bundle?) {
        super.onPlayFromUri(uri, extras)

        val bundle = extras

        info {
            bundle?.get(Config.MusicConfig.MUSIC_TRACKS)
            bundle?.get(Config.MusicConfig.MUSIC_TRACK_POSITION)
        }
    }

抛出

android.os.BadParcelableException: ClassNotFoundException when unmarshalling:

0 个答案:

没有答案