Sakkeer Hussain
Sakkeer Hussain

Reputation: 459

Can't Draw Recycled Bitmap

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();
    }`

Upvotes: 1

Views: 203

Answers (2)

Gunnar Karlsson
Gunnar Karlsson

Reputation: 28470

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.

Upvotes: 2

murielK
murielK

Reputation: 1020

remove

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

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

Upvotes: 0

Related Questions