For example, when using Alarmmanager
1Alarmmanager alarmmgr =(Alarmmanager) Mcontext2 . Getsystemservice (context.alarm_service);3Intent Intent =NewIntent (alarm_alert);4 //Intent.setextrasclassloader (DBTask.class.getClassLoader ());5Bundle mbundle=NewBundle ();6 mbundle.putparcelable (alarmmereceiver.db_task_key,task);7 Intent.putextras (mbundle);8 intId=integer.valueof (task.id);9Pendingintent pendintent =Pendingintent.getbroadcast (Ten Mcontext.getapplicationcontext (), ID, intent, One pendingintent.flag_update_current); A LongTriggerattime =Task.time; -Alarmmgr.set (Alarmmanager.rtc_wakeup, Triggerattime, pendintent);
Intent a Parcelable object via line 6th (no problem in parcelable)
Report android.os.BadParcelableException:ClassNotFoundException when unmarshalling error can be added
Intent.setextrasclassloader (DBTask.class.getClassLoader ());
The reason is Android.platform.frameworks.base/core/java/android/content/intent.java.
5052Try {5053 Bundle newb =NewBundle (Other.mextras);5054Newb.putall (Mextras);5055 Mextras =newb;5056}Catch(RuntimeException e) {5057//Modifying the extras can cause us to unparcel the contents5058//of the bundle, and if we do this on the system process that5059//May fail. We really should handle this (i.e., the Bundle5060//impl shouldn ' t is on top of a plain map), but is now just5061//ignore it and keep the original contents.:(5062 LOG.W ("Intent", "Failure filling in extras", e);5063}
android in Custom Object serialization problems have two choices one is parcelable and the other is serializable.
A serialization reason:
1. Persisted object, saves the object's byte sequence to the local file;
2. Passing objects in the network through a serialized object;
Second, the following principles can be used to select which of these:
1. When using memory, parcelable analogy serializable high performance, so we recommend the use of Parcelable class.
2.Serializable generates a large number of temporary variables when serializing, causing frequent GC.
3.Parcelable cannot be used to store data on disk, because Parcelable does not guarantee the continuity of the data in the event of a change in the outside world. Although serializable efficiency is low, it is not advocated, but in this case, it is recommended that you use serializable.