1

Is this code has any error ? When I run this i got an error here as Can't draw recycled bitmap. I got this code from while i am reading through stack overflow itself.

`Bitmap bm = BitmapFactory.decodeFile(urlString,options);
 imgDisplay.setImageBitmap(bm);
    if(bm!=null){
        bm.recycle();
    }`
Sakkeer Hussain
  • 459
  • 6
  • 19

2 Answers2

2

You should only call call recycle() in your Activity's onDestroy(), and only if you know why you need to. Normally it's not necessary, unless you're facing e.g. memory issues. Your current recycle() may be called before the View's onDraw() is called, or there may be other code that triggers a draw call on the View, which would cause the error. So I suggest you remove the recycle() call as a starting point.

Gunnar Karlsson
  • 28,350
  • 10
  • 68
  • 71
0

remove

if(bm!=null){
        bm.recycle();
    }`

recycle bitmap only if is not used or referred at all anymore.

murielK
  • 1,000
  • 1
  • 10
  • 21