将位图动态放入小部件中时活页夹事务失败
谁能告诉我绑定程序事务失败错误的原因吗?我可以在 logcat 中看到此错误消息。 我在尝试将位图动态放入小部件时收到此错误...
Can anybody tell me the reason for failed binder transaction error? I can see this error message in logcat.
I am getting this error while trying to put an bitmap dynamically in a widget...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这是因为对 RemoteView 的所有更改都是序列化的(例如 setInt 和 setImageViewBitmap )。位图也被序列化到内部包中。不幸的是,这个捆绑包的大小限制非常小。
您可以通过以下方式缩小图像尺寸来解决这个问题:
选择足够小的 newHeight (屏幕上每个方块应为约 100)并将其用于您的小部件,您的问题将得到解决:)
This is caused because all the changes to the RemoteViews are serialised (e.g. setInt and setImageViewBitmap ). The bitmaps are also serialised into an internal bundle. Unfortunately this bundle has a very small size limit.
You can solve it by scaling down the image size this way:
Choose newHeight to be small enough (~100 for every square it should take on the screen) and use it for your widget, and your problem will be solved :)
您可以将位图压缩为字节数组,然后在另一个活动中将其解压缩,如下所示。
压缩!!
解压!!
You can compress the bitmap as an byte's array and then uncompress it in another activity, like this.
Compress!!
Uncompress!!
Binder 事务缓冲区的固定大小有限,目前为 1Mb,由进程中所有正在进行的事务共享。因此,当有许多事务正在进行时,即使大多数单个事务的大小适中,也会引发此异常。
请参考此链接
The Binder transaction buffer has a limited fixed size, currently 1Mb, which is shared by all transactions in progress for the process. Consequently this exception can be thrown when there are many transactions in progress even when most of the individual transactions are of moderate size.
refer this link
请参阅我的答案此
线。
intent.putExtra("Some string",very_large_obj_for_binder_buffer);
通过将大元素从一个活动传输到另一活动,您超出了活页夹事务缓冲区。
See my answer in this
thread.
intent.putExtra("Some string",very_large_obj_for_binder_buffer);
You are exceeding the binder transaction buffer by transferring large element(s) from one activity to another activity.
我通过将图像存储在内部存储上然后使用 .setImageURI() 而不是 .setBitmap() 解决了这个问题。
I have solved this issue by storing images on internal storage and then using .setImageURI() rather than .setBitmap().
正确的方法是使用
setImageViewUri()
(速度较慢)或setImageViewBitmap()
并在每次更新通知时重新创建RemoteView
。The right approach is to use
setImageViewUri()
(slower) or thesetImageViewBitmap()
and recreatingRemoteView
s every time you update the notification.