0

Possible Duplicate:
failed binder transaction on widget update

Whenever I update my widget Imageview using the bitmap, the Logcat shows the following error,

"Javabinder , FAILED BINDER TRANSACTION"

I searched in the internet and understood that it is due to memory issue.

I am using the following code to update the ImageView.

private void update(Context context) {
    Log.d("Configure", "updatestart");
    remoteViews.setImageViewBitmap(R.id.clockview,
            buildUpdate("CURRENTTIME", c));
    awm.updateAppWidget(awID, remoteViews);
}

And the buildUpdate function:

public Bitmap buildUpdate(String time, Context context) {


    Log.d("ConfigureApp","Buildupdate_fn ---" + "start");
    date = new Date();
    sec = (float) date.getSeconds();
    min = (float) date.getMinutes();
    hour = (float) date.getHours() + min / 60.0f;

    bitmap = Bitmap.createBitmap(200, 200, Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint p = new Paint();
    p.setAntiAlias(true);
    p.setColor(0xFFFF0000);
    p.setStrokeWidth(2);
    canvas.drawLine(
            x,
            y,
            (float) (x + (r - 15)
                    * Math.cos(Math
                            .toRadians((hour / 12.0f * 360.0f) - 90f))),
            (float) (y + (r - 10)
                    * Math.sin(Math
                            .toRadians((hour / 12.0f * 360.0f) - 90f))), p);
    canvas.save();
    p.setColor(0xFF0000FF);
    canvas.drawLine(
            x,
            y,
            (float) (x + r
                    * Math.cos(Math.toRadians((min / 60.0f * 360.0f) - 90f))),
            (float) (y + r
                    * Math.sin(Math.toRadians((min / 60.0f * 360.0f) - 90f))),
            p);
    canvas.save();
    p.setColor(0xFFA2BC13);
    canvas.drawLine(
            x,
            y,
            (float) (x + (r + 10)
                    * Math.cos(Math.toRadians((sec / 60.0f * 360.0f) - 90f))),
            (float) (y + (r + 15)
                    * Math.sin(Math.toRadians((sec / 60.0f * 360.0f) - 90f))),
            p);

    remoteViews.setTextViewText(R.id.mycity, Float.toString(x));
    return bitmap;
}

Please tell me how to avoid this error.:( Is there any other way to do the same?

Thanks in advance,

Community
  • 1
  • 1

1 Answers1

2

If this is memory error, then try to reuse the bitmap, instead of creating the new on every time buildUpdate() is called.

Also, AFAIK, canvas.save() is only useful if you actually call canvas.restore().

Peter Knego
  • 79,991
  • 11
  • 123
  • 154
  • From the post http://stackoverflow.com/questions/7888890/failed-binder-transaction-on-widget-update I understood that we can save it in a folder and just calling will avoid the error. But how to do that? – Jihana Maharooft Dec 11 '11 at 09:16