Android.os.BadParcelableException:ClassNotFoundException when unmarshalling: Solutions

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.