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 ...
随机推荐
- git使用问题汇总
2015.11.29 一.git clone 出现如下问题: 解决方案:添加一个ssh keys.步骤如下: 1.生成一个ssh-key(图片来自网络) 2.找到“Your identificatio ...
- js简单的工厂模式
<!DOCTYPE html> <html> <head> <title></title> </head> <body&g ...
- BZOJ-1013 球形空间产生器sphere 高斯消元+数论推公式
1013: [JSOI2008]球形空间产生器sphere Time Limit: 1 Sec Memory Limit: 162 MB Submit: 3662 Solved: 1910 [Subm ...
- EasyUI queryParams属性 在请求远程数据同时给action方法传参
http://www.cnblogs.com/iack/p/3530500.html?utm_source=tuicool EasyUI queryParams属性 在请求远程数据同时给action方 ...
- VS2010+OpenCV2.4.6永久性配置方法
1. 配置OpenCV环境变量 计算机->(右键)属性,出现如图1所示界面 单击“高级系统设置”,选中高级(标签)出现如图2所示界面 单击右下方的“环境变量”,弹出如图3所示界面,注意这里最好用 ...
- 一个令人蛋疼的 Microsoft.AspNet.FriendlyUrls
我一个项目都基本上做完了,结果部署到我服务器的时候结果一直报404 找不到 一看global.asax有个路由注册的代码 public static void RegisterRoutes(Route ...
- Yii2事件
namespace app\components; use yii\base\Component; use yii\base\Event; class MessageEvent extends Eve ...
- C# 排序算法记录
class Program { static void Main(string[] args) { , , , , , , , , -, , , }; //假设一个最小的值 ]; ; i < a ...
- iOS-解决iOS8及以上设置applicationIconBadgeNumber报错的问题
在IOS7中设置applicationIconBadgeNumber不会有什么问题,但是直接在IOS8中设置applicationIconBadgeNumber会报错.因为在IOS8中要想设置appl ...
- webexam项目杂记
sql 语句 数据库 本身 有数据类型的区分,对于mysql的字符串默认的用单引号''来表示,因此,整个sql 语句就要用双引号来括. 如: $sql = "SELECT * FROM us ...