android - Bitmap.recycle() - "IllegalArgumentException: Cannot draw recycled bitmaps" -


in documentation, titled "managing bitmap memory" can find following statement:

caution: should use recycle() when sure bitmap no longer being used. if call recycle() , later attempt draw bitmap, error: "canvas: trying use recycled bitmap".

so, means "no longer"?

i call setimagedrawable(drawable) in fragments oncreateview(...) method. , call recycle() on drawable's bitmap in fragment's onstop(). when user leaves fragment launching activity bitmap recycled. when user comes previous fragment, oncreateview() called again, resulting in new call "setimagedrawable(drawable)". , throws:

illegalargumentexception: cannot draw recycled bitmaps 

so, still seem in "no longer" context. when new bitmap, not recycled? after fragment , activity have been destroyed?

so, means "no longer"?

no longer means not going use same reference of bitmap.

as told recycling bitmaps on onstop(), try inside onstop()

   if(bitmap!=null)    {       bitmap.recycle();       bitmap=null;    } 

bitmap , outofmemory in android

watch first 20 minuts of official video if want make day - http://www.youtube.com/watch?v=_cruqy55hok


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -