Android开发Error(建议收藏下来以备不时之需)android.os.TransactionTooLargeException: data parcel size xxxx bytes
16lz
2021-01-24
前言
该异常触发的概率不大,很多Android猴子可能都没遇到过
但是真的出现的时候别不知道怎么解决
什么情况出现
界面跳转 intent 中的数据内容较多
Android调用系统裁减图片
批量插入大量数据到数据库(我是这种情况,一下主要针对批量插入数据库讲解)
系统源码
源码位置:android/frameworks/base/core/jni/android_util_Binder.cpp
是的你没看错,在以上三种传输中 大于200K就会报错
case FAILED_TRANSACTION: { ALOGE("!!! FAILED BINDER TRANSACTION !!! (parcel size = %d)", parcelSize); const char* exceptionToThrow; char msg[128]; // TransactionTooLargeException is a checked exception, only throw from certain methods. // FIXME: Transaction too large is the most common reason for FAILED_TRANSACTION // but it is not the only one. The Binder driver can return BR_FAILED_REPLY // for other reasons also, such as if the transaction is malformed or // refers to an FD that has been closed. We should change the driver // to enable us to distinguish these cases in the future. if (canThrowRemoteException && parcelSize > 200*1024) { --------- 在这里是有判断的 // bona fide large payload exceptionToThrow = "android/os/TransactionTooLargeException"; snprintf(msg, sizeof(msg)-1, "data parcel size %d bytes", parcelSize); } else { // Heuristic: a payload smaller than this threshold "shouldn't" be too // big, so it's probably some other, more subtle problem. In practice // it seems to always mean that the remote process died while the binder // transaction was already in flight. exceptionToThrow = (canThrowRemoteException) ? "android/os/DeadObjectException" : "java/lang/RuntimeException"; snprintf(msg, sizeof(msg)-1, "Transaction failed on small parcel; remote process probably died"); } jniThrowException(env, exceptionToThrow, msg); } break;
解决方案
intent 传递的数据过大 把大型的序列化集合或者Bitmap缓存 传递缓存路径即可
Android调用系统裁减图片 Bitmap 过大 这个时候只能通过MediaStore.EXTRA_OUTPUT设置裁减图片保存位置,只传递图片路径,不直接传bitmap对象。
批量插入大量数据到数据库 改成分多批 根据自己实际数据量 去衡量每次批量传入多少合适 比如要批量传入100000条数据 每张表的数据还特别多 可以以500条为一批 按批插入
更多相关文章
- android 加载大图长图失真或者不显示。
- Android显示gif格式图片
- Android训练课程(Android(安卓)Training) - 使用Volley传输网络
- Android自定义时间控件不可选择未来时间
- 关于Android(安卓)O系统短信拦截的流程
- 高亮的关键字
- Android(安卓)Adapter的那些事
- [置顶] Android仿人人客户端(v5.7.1)——应用主界面之左侧面板UI实
- Android数据共享机制ContentProvider