Failed Binder Transaction When Putting an Bitmap Dynamically in a Widget

Avoiding FAILED BINDER TRANSACTION error when updating lots of widget bitmaps

The best workaround I found was to use setImageURI on the ImageView objects using

remoteViews.setUri(R.id.myImageView, "setImageURI", "file://blahblahblah.png");

Here is the full discussion from Android Developers group

Failed Binder Transaction is Ruining Entire Widget

PackageManager methods, like getInstalledPackages(), can result in a binder transaction error, if the sum total of information being returned is greater than 1MB.

One way to mitigate this is to pass in no flags (e.g., skip PackageManager.GET_ACTIVITIES) to reduce the amount of data in the first call. Then, for those packages where you need the additional detail, call getPackageInfo() to get the details for a specific package. While this does involve multiple IPC round-trips, and therefore is slower, it will help prevent you from blowing out the 1MB-per-transaction limit.

FAILED BINDER TRANSACTION with both bitmap or bytearray

How can I pass the image data between activities?

You don't. Either:

  • These should be combined into one activity, or

  • You should have some sort of image cache that the two activities share, where you pass the identifier to the cache entry

Still get error FAILED BINDER TRANSACTION although have compressed it

I think you are not compressing the bmp where you should do it.

    submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent returnIntent = new Intent();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] bytes = stream.toByteArray();
returnIntent.putExtra("BMP", bytes);
setResult(Activity.RESULT_OK, returnIntent);
finish();

}
});

Then you should to uncompress where you need to show the image

byte[] bytes = data.getByteArrayExtra("BMP");
Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
imageView.setImageBitmap(bmp);


Related Topics



Leave a reply



Submit