Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top