android.os.BadParcelableException: ClassNotFoundException when unmarshalling:解决办法
例如在用AlarmManager的时候

AlarmManager alarmMgr = (AlarmManager) mContext
.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(ALARM_ALERT);
// intent.setExtrasClassLoader(DBTask.class.getClassLoader());
Bundle mBundle=new Bundle();
mBundle.putParcelable(AlarmMeReceiver.DB_TASK_KEY,task);
intent.putExtras(mBundle);
int id=Integer.valueOf(task.id);
PendingIntent pendIntent = PendingIntent.getBroadcast(
mContext.getApplicationContext(), id, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
long triggerAtTime = task.time;
alarmMgr.set(AlarmManager.RTC_WAKEUP , triggerAtTime, pendIntent);

通过第6行 intent传提一个Parcelable对象 (Parcelable里面没有问题)
报android.os.BadParcelableException: ClassNotFoundException when unmarshalling错误可以加上
intent.setExtrasClassLoader(DBTask.class.getClassLoader());
原因是android.platform.frameworks.base/core/java/android/content/Intent.java

5052 try {
5053 Bundle newb = new Bundle(other.mExtras);
5054 newb.putAll(mExtras);
5055 mExtras = newb;
5056 } catch (RuntimeException e) {
5057 // Modifying the extras can cause us to unparcel the contents
5058 // of the bundle, and if we do this in the system process that
5059 // may fail. We really should handle this (i.e., the Bundle
5060 // impl shouldn't be on top of a plain map), but for now just
5061 // ignore it and keep the original contents. :(
5062 Log.w("Intent", "Failure filling in extras", e);
5063 }

android 中自定义的对象序列化的问题有两个选择一个是Parcelable,另外一个是Serializable。
一 序列化原因:
1.永久性保存对象,保存对象的字节序列到本地文件中;
2.通过序列化对象在网络中传递对象;
3.通过序列化在进程间传递对象。
二 至于选取哪种可参考下面的原则:
1.在使用内存的时候,Parcelable 类比Serializable性能高,所以推荐使用Parcelable类。
2.Serializable在序列化的时候会产生大量的临时变量,从而引起频繁的GC。
3.Parcelable不能使用在要将数据存储在磁盘上的情况,因为Parcelable不能很好的保证数据的持续性在外界有变化的情况下。尽管Serializable效率低点, 也不提倡用,但在这种情况下,还是建议你用Serializable 。
android.os.BadParcelableException: ClassNotFoundException when unmarshalling:解决办法的更多相关文章
- 配置Android环境遇到的问题及解决办法
配置Android环境遇到的问题及解决办法: 1 环境安装地址 http://pan.baidu.com/s/1jGzNzyI 2 其他: 2.1 安装 2.1.1 安装JDK,JRE 成功安装之后, ...
- import android.support.v4或者import android.support.v7提示导入错误解决办法
转自: http://blog.csdn.net/forandever/article/details/37655139 在使用Eclipse开发andriod程序时,程序中提示import and ...
- Andriod学习笔记2:“Your content must have a ListView whose id attribute is 'android.R.id.list'”问题的解决办法
问题描述 activity_main.xml代码如下: <?xml version="1.0" encoding="utf-8"?> <Lin ...
- mac: vmware fusion中cent os启动假死的解决办法
环境: mac os X 10.9.2 + vmware 6.0.2 + cent OS 6.5 minimal 现象: Booting CentOS (2.6.32-358.e.l6.i686) i ...
- Android Studio生成javadoc出错的解决办法
一般使用Android Studio生成javadoc会有两个问题: 空指针异常 文档乱码 解决办法如下: 第1个问题:Tools --> Generate JavaDoc -->打开对话 ...
- Android开发遇到的异常及解决办法
Android开发遇到的错误及解决方法1. Unable to resolve target 'android-7' 解决方案: 修改工程目录下的default.properties文件里的内容tar ...
- Android SDK Manager无法更新的解决办法
Fetching https://dl-ssl.google.com/android/repository/addons_list-1.xmlFailed to fetch URL https://d ...
- Android 开发遇到的问题及解决办法
Failed to resolve: com.android.support:appcompat-v7:23.4.0 问题解决办法: 1.在Android SDK Manager中找到对应的SDK版本 ...
- MAC上使用maven打android的包,报错:No Android SDK path could be found. 解决办法
对android工程运行mvn compile出现如下信息: No Android SDK path could be found. You may configure it in the pom u ...
随机推荐
- Linux进程管理工具——supervisor
介绍 Supervisord是用Python实现的一款非常实用的进程管理工具 安装 这里用源码 supervisor-.tar.gz .tar.gz cd supervisor- sudo pytho ...
- RHCS配置web高可用集群
基本条件三台主机 10.37.129.5 web1.xzdz.hk web1 10.37.129.6 web2.xzdz.hk web2 10.37.129.4 luci.xzdz.hk luci 其 ...
- oracle使用存储过程实现日志记录.sql
--这段sql语句是用来实现oracle后台记录操作日志的,代替或者补充应用系统的操作日志. --1.对应的日志记录表----------------------------------------- ...
- Hive简单优化;workflow调试
1. 定义job名字 SET mapred.job.name='customer_rfm_analysis_L1'; 这样在job任务列表里可以第一眼找到自己的任务. 2. 少用distinct, 尽 ...
- BZOJ3626 LCA
Description 给出一个n个节点的有根树(编号为0到n-1,根节点为0).一个点的深度定义为这个节点到根的距离+1. 设dep[i]表示点i的深度,LCA(i,j)表示i与j的最近公共祖先. ...
- POJ2187 Beauty Contest
Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, ea ...
- POJ2135 Farm Tour
Farm Tour Time Limit: 2MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Description ...
- Model1模式的学生信息增删改查
Student.java package entity; public class Student { private int stuid; private String stuname; priva ...
- hihocoder1187 Divisors
传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Given an integer n, for all integers not larger than n, f ...
- Omnet++ 4.0 入门实例教程
http://blog.sina.com.cn/s/blog_8a2bb17d01018npf.html 在网上找到的一个讲解omnet++的实例, 是4.0下面实现的. 我在4.2上试了试,可以用. ...