0

I'm making a battery widget, and to avoid having 20 separate PNG files for the different levels I've got one PNG which I rotate to 20 positions. On Android 3.x+ this is easy, as the ImageView element as a rotate property. For backwards compatibility I am generating the other images using a matrix, as such:

if(Build.VERSION.SDK_INT < 11) {
        Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.battery_green);
        Matrix m = new Matrix();
        for(int i = 0; i < 20; i++) {
            String idName = "batt_s_"+i;
            int id = context.getResources().getIdentifier(idName, "id", context.getPackageName());
            m.setRotate((i * 18) - 8);
            Bitmap newBmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), m, true);
            myViews.setImageViewBitmap(id, newBmp);
        }
    }

This doesn't work, however, because although the image itself is fairly small, doing this 20 times exceeds the binder limit, and I get !!! FAILED BINDER TRANSACTION !!!. A single one of my generated bitmaps will send just fine, I feel like I need a way to break my one big transaction into 20 individual ones somehow. There has to be some way around this limitation so I can support my users on Android 2.x. Any thoughts?

I have to add, the original PNG file that I'm modifying is 903 bytes on disk. My transaction that's blowing the binder limit is 1,271,808 bytes. I'll assume this is because generating a Bitmap object is actually created a BMP file, which are of course much larger in size than a PNG. Is there a way I can avoid using bitmaps altogether?

Nick
  • 6,900
  • 5
  • 45
  • 66

1 Answers1

0

Maybe this can help:

This is a workaround for getting work done within the small binder limit available.

https://groups.google.com/forum/#!topic/android-developers/KKEyW6XdDvg/discussion

Rahul Bisht
  • 482
  • 3
  • 5
  • I've read that whole thread multiple times. I haven't found anything that really helps me. I'm generating the new bitmaps on the fly, so I can't use a URI as far as I know, and I've tried scaling the bitmap before I send it, and changing its density, but nothing has worked. – Nick Jan 02 '13 at 06:22
  • Just wondering...would setting a delay of x milliseconds between each transaction help..? – Rahul Bisht Jan 02 '13 at 06:39
  • "The Binder transaction buffer has a limited fixed size, currently 1Mb, which is shared by all transactions in progress for the process." so a delay shouldn't help. What I really need is a way to force the transaction buffer to send and clear between iterations of my loop – Nick Jan 02 '13 at 06:58
  • I ended up saving the images to disk as I generated them and then using URIs, as suggested in the link you provided, so I suppose you get the correct answer marker. Thank you! For some extra details on what I had to do, look [here](http://stackoverflow.com/questions/14146291/resolveuri-failing-on-app-private-data-file/14147125#comment19594768_14147125) – Nick Jan 03 '13 at 22:19