1

I'm using org.jetbrains.kotlin.android.extensions to parcel data.

This is my data class

@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

This is how I send my data across

  override fun playTrack(position: Int, musicList: ArrayList<MusicTrack>) {
    info { musicList }
    val bundle = bundleOf(
            Config.MusicConfig.MUSIC_TRACKS to musicList,
            Config.MusicConfig.MUSIC_TRACK_POSITION to position)


    MediaControllerCompat.getMediaController(this).transportControls.playFromUri(Uri.parse("Hack"), bundle)
}

Then consuming the parcel like

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

        val tracks = extras?.getParcelable<MusicTrack>(Config.MusicConfig.MUSIC_TRACKS) as ArrayList<*>

        info { tracks }

    }

Which throws the above error android.os.BadParcelableException: ClassNotFoundException when unmarshalling:

But, when I try to consume it in an activity with

    val songsList = intent.getStringArrayListExtra("Extras")
    info { songsList }

It works! Can anyone help me here?

Veeresh Charantimath
  • 4,641
  • 5
  • 27
  • 36

2 Answers2

1

You're trying to read a single MusicTrack, but you have a list of them in a Bundle. You need to call getParcelableArrayList<MusicTrack>.

Miha_x64
  • 5,973
  • 1
  • 41
  • 63
-1

Try this in Buid.gradle this solved my issue

apply plugin: 'org.jetbrains.kotlin.android.extensions'
androidExtensions {
    experimental = true
}
Siddharth Patel
  • 205
  • 1
  • 13