0

I have this error when I run this code. It says java.lang.RuntimeException trying to use recycled bitmap. They say I should use Bitmap.recycle() but I'm having this error. Is my code correct?

Here is my code:

ImageView image = (ImageView) findViewById(R.id.imageView1);
Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
image.setImageBitmap(bMap);
bMap.recycle();
pb2q
  • 58,613
  • 19
  • 146
  • 147
nelzkie
  • 235
  • 1
  • 3
  • 15
  • [Have a look at this](http://stackoverflow.com/q/477572/940096) – Praveenkumar Jun 25 '12 at 05:18
  • Please [search](http://stackoverflow.com/search?q=+runtimeexception+trying+to+use+a+recycled+bitmap) before asking. [See also](https://www.google.com/search?q=site%3Astackoverflow.com+runtimeexception+canvas+trying+to+use+a+recycled+bitmap). – pb2q Jun 25 '12 at 05:19

1 Answers1

0

Check out this code:

if (null != bMap && !bMap .getBitmap().isRecycled()) 
{
    bMap .getBitmap().recycle();
} else {
    log("bitmap is already recycled");
}

I think it will help you.

pb2q
  • 58,613
  • 19
  • 146
  • 147
Md Abdul Gafur
  • 6,213
  • 2
  • 27
  • 37