notification复用中抛出can not parcel recyle’s bitmap
来源:互联网 发布:定时短信软件 编辑:程序博客网 时间:2024/04/26 00:28
由于对android重用思想的根深蒂固,所以我在使用通知的使用并不是stop之后再次start,而是只存在一个对象,直接startforgeound,
但是在remoteview中将之前bitmap.recyle时,会出现can not parcel recyle’s bitmap,bitmap
原始代码是这样的.
bitmap(之前通知现实的图片)
bitmap.recyle();
mRemoteView.setImageViewResource(R.id.notification_bg, R.drawable.log);
startForeground();
foreground死掉了,为什么呢?我发现每次执行与bitmap相关的方法,remoteviews中的bitmapcache都会去获取ID,这个ID就是bitmapcache中的index,因为removateviews的缺陷,导致并非我们设置bitmap为null时便会移除原本的action(remoteviews中的内部类,每次执行关于bitmap的方法都会new一个新的,添加到默认数组中),这就导致bitmapcache中的arraylist<bitmap>只增不减,为此我们无法将bitmap进行recyle,如果我们recyle便会抛出can not parcel recyle’s bitmap 错误,因为它竟然将bitmapcache中的arraylist<bitmap>全部parcel,如果我们不recyle,就会导致gc亚历山大的问题(我是想重用notification的,虽然google不建议我们重用,因为可能引起ANR,但是呢,重用如果只有单一功能的notification,重用还是有价值的,毕竟用户不希望在重复刷新nofication时,内存直升太过明显,那显然是很操蛋的体验,不要太相信GC线程,比如service只用了2M,而由于频繁操作,heap到达了10M,那么这个10M显示在应用程序列表里会持续很长时间),解决方法很简单:
private boolean removeBitmapCache() {try {Object obj = Tool.getField(mRemoteView, "mBitmapCache").get(mRemoteView);if (obj != null) {List<Bitmap> mps = (List<Bitmap>) Tool.getField(obj, "mBitmaps").get(obj);if (mps != null) {mps.clear();return true;}}} catch (Exception e) {e.printStackTrace();}return false;}
使用java反射,得到bitmapcache中arraylist,进行清空.
- notification复用中抛出can not parcel recyle’s bitmap
- Bitmap的recyle()方法
- hadoop运维--ha抛出journalnode can not write
- Android4.0 Bitmap Parcel传输源码分析
- mysql抛出Value '0000-00-00' can not be represented as java.sql.Timestamp异常
- Recyle.xaml
- how can handle push notification when my app is not running
- Parcel
- Parcel
- Parcel
- Android6.0 Bitmap存储以及Parcel传输源码分析
- The Activity's LayoutInflater already has a Factory installed so we can not install AppCompat's
- StructType can not accept object %r in type %s" % (obj, type(obj)))
- mysql时间格式默认为null抛出java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java
- Could not read input channel file descriptors from parcel
- Could not read input channel file descriptors from parcel.
- 解决Could not read input channel file descriptors from parcel
- RunTimeException-Could not read input channel file descriptors from parcel
- 2.Enable ADB integration' to be enabled.
- 从头学android_GET 和 POST 网络请求
- Android实现正方系统的登录以及课程表,成绩获取和空课室的查询(二)
- tp框架多个OR与And连用查询笔记
- SDWebImage异步下载和缓存的源码剖析
- notification复用中抛出can not parcel recyle’s bitmap
- 10、正则表达式匹配练习
- CF Watchmen 【思维+数学】
- 自动化发布项目之jenkins + git + maven 自动化部署一个web项目
- linux下的进程控制块task_struct详解
- Android Studio详细使用教程
- HYSBZ 1036 树的统计Count(树链剖分)
- hdu1349(题解) Minimum Inversion Number
- 解决Git项目不能Pull