问题描述
我使用自定义Parcelable一些数据来进行一个BroadcastReceiver。这是我做的:
I use a custom Parcelable to carry some data to a BroadcastReceiver. Here is what i do:
我登记我的意图,并设置额外Parcelable它与一个额外的类加载器(intent.setExtraClassLoader(..))。接着我安排播出的执行通过AlarmManager。
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.
所以当AlarmManager触发它看起来在我的意图,其包裹,它无法处理,因为它不使用提供的类加载器(因为它的接缝)。
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).
我觉得类加载器丢失时Inten.fillIn copys意图到一个新的(见堆栈跟踪)。
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: com.company.project.MyParcelable
02-21 21:09:25.214: WARN/Intent(52): at android.os.Parcel.readParcelable(Parcel.java:1822)
02-21 21:09:25.214: WARN/Intent(52): at android.os.Parcel.readValue(Parcel.java:1713)
02-21 21:09:25.214: WARN/Intent(52): at android.os.Parcel.readMapInternal(Parcel.java:1947)
02-21 21:09:25.214: WARN/Intent(52): at android.os.Bundle.unparcel(Bundle.java:169)
02-21 21:09:25.214: WARN/Intent(52): at android.os.Bundle.putAll(Bundle.java:242)
02-21 21:09:25.214: WARN/Intent(52): at android.content.Intent.fillIn(Intent.java:4530)
02-21 21:09:25.214: WARN/Intent(52): at com.android.server.am.PendingIntentRecord.send(PendingIntentRecord.java:185)
02-21 21:09:25.214: WARN/Intent(52): at android.app.PendingIntent.send(PendingIntent.java:400)
02-21 21:09:25.214: WARN/Intent(52): at com.android.server.AlarmManagerService$AlarmThread.run(AlarmManagerService.java:636)
那么,有没有解决这个问题,什么办法?任何帮助将是AP preciated。
So is there any way around that problem? Any help would be appreciated.
感谢
推荐答案
将在实际应用中的 com.company.project.MyParcelable
,而不是做什么游戏,你是玩类加载器。然后,它应该从发送方和意向收件人
。
Put com.company.project.MyParcelable
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
.
这篇关于ClassNotFoundException的时候使用自定义Parcelable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!