Hi,

In my app, I have home screen widgets which have an ImageView and a
TextView. For each one, I want to put a different bitmap for the
ImageView.

The problem is that sometimes I get this exception, saying that the
widget engine has tried to draw recycled bitmaps:

java.lang.RuntimeException: Canvas: trying to use a recycled bitmap
android.graphics.bit...@4628cf78
       at android.graphics.Canvas.throwIfRecycled(Canvas.java:955)
       at android.graphics.Canvas.drawBitmap(Canvas.java:1044)
       at
android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:323)
       at android.widget.ImageView.onDraw(ImageView.java:923)
       at android.view.View.draw(View.java:6739)
[...]

The stacktrace continues but never references my code. I have tried to
keep a static HashMap with all the Bitmaps needed for the widgets and
it still keeps happening. I have also tried to generate bitmaps,
saving them to SD card and loading them this way:

            Bitmap bitmap =
BitmapFactory.decodeResource(context.getResources(),
R.drawable.widget_btn);
            Bitmap bitmap2 =
Bitmap.createBitmap(BitmapManager.setColor(bitmap, w.color));

            File f = new File(Util.getBitmapFolder());
            f.mkdirs();
            FileOutputStream out = new
FileOutputStream(Util.buildWidgetBitmapFilename(w.color));
            bitmap2.compress(Bitmap.CompressFormat.PNG, 90, out);
            out.close();

            Uri uri =
Uri.parse(Util.buildWidgetBitmapFilename(w.color));
            views.setImageViewUri(R.id.image, uri);

But it is still happening. Who is recycling the bitmaps? Is there a
way to avoid it? I can post more code if necessary, this error is
driving me crazy.

Thank you!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to