ClassNotFoundException when using custom Parcelable

I use a custom Parcelable to carry some data to a BroadcastReceiver. Here is what i do:

I register my intent and set the extra Parcelable on it along with an extra classloader (intent.setExtraClassLoader(..)). Next i schedule the execution of the broadcast via an AlarmManager.

  • Bring application back to front
  • Get caps lock state in Android
  • Caching overlays by rounding coordinates rectangles - how?
  • TextView gravity
  • How to get the first name and last name from Android contacts?
  • Scrolling is not working with CoordinatorLayout + parallax image + BottomSheetLayout
  • So when the AlarmManager fires it looks at my intent with its parcel which it can not process since it doesn’t use the supplied classloader (as it seams).

    I think the classloader gets lost when Inten.fillIn copys the intent to a new one (see stack trace).

    02-21 21:09:25.214: WARN/Intent(52): android.os.BadParcelableException: ClassNotFoundException when unmarshalling:
    02-21 21:09:25.214: WARN/Intent(52):     at android.os.Parcel.readParcelable(
    02-21 21:09:25.214: WARN/Intent(52):     at android.os.Parcel.readValue(
    02-21 21:09:25.214: WARN/Intent(52):     at android.os.Parcel.readMapInternal(
    02-21 21:09:25.214: WARN/Intent(52):     at android.os.Bundle.unparcel(
    02-21 21:09:25.214: WARN/Intent(52):     at android.os.Bundle.putAll(
    02-21 21:09:25.214: WARN/Intent(52):     at android.content.Intent.fillIn(
    02-21 21:09:25.214: WARN/Intent(52):     at
    02-21 21:09:25.214: WARN/Intent(52):     at
    02-21 21:09:25.214: WARN/Intent(52):     at$

    So is there any way around that problem? Any help would be appreciated.


    Related posts:

    Android: textview hyperlink
    My app is not available for tablet device on Google play
    Calling native method twice of third party library in an Activity causes the Android application to ...
    Android plurals treatment of “zero”
    match_parent width does not work in RecyclerView
    Custom checkbox style in dialog
  • How to include JAR dependency into an AAR library
  • Play video on the android recorded from the iPhone
  • This text field does not specify an inputType or a hint
  • Pick an email using AccountPicker.newChooseAccountIntent
  • My service always getting Waited long enough for: ServiceRecord error in Kitkat
  • Android: SQLite transactions when using ContentResolver
  • 3 Solutions collect form web for “ClassNotFoundException when using custom Parcelable”

    Put in the actual application, instead of doing whatever games you are playing with classloaders. Then, it should be available from both the sender and recipient of the Intent.

    Seems that you face with the issue described here:

    There is a workaround described in one of comments under that link: put your custom Parcelable into an additional Bundle. Due to the fact that Bundle internals are not touched until it’s needed, such an Intent can be delivered to your app, since nobody will try to unmarshal your class outside your app.

      Bundle hackBundle = new Bundle();
      hackBundle.put("key", myParcelable);
      intent.putExtra("bundleKey", hackBundle);

    There is also a bug in Android that can explain this issue in case you try to pass an intent another intent :

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.