ERROR; Canvas: trying to use a recycled bitmap android.graphics.Bitmap

1

I am getting a bitmap from a gridview and displaying it in another activity, then when I open 3x to another activity the app hangs and closes.

First acitivy

view.buildDrawingCache();

                    Bitmap bitmap = view.getDrawingCache();

Second

Bitmap bitmap = getArguments().getParcelable("SEU_BITMAP");

Can you help me with this?

03-16 14:17:50.890: E/AndroidRuntime(11180): FATAL EXCEPTION: main
03-16 14:17:50.890: E/AndroidRuntime(11180): Process: com.ompex.zueriabrasil, PID: 11180
03-16 14:17:50.890: E/AndroidRuntime(11180): java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@45039080
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.graphics.Canvas.throwIfCannotDraw(Canvas.java:1084)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.GLES20Canvas.drawBitmap(GLES20Canvas.java:844)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:490)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.widget.ImageView.onDraw(ImageView.java:1019)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.draw(View.java:14613)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.getDisplayList(View.java:13510)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.getDisplayList(View.java:13552)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.draw(View.java:14330)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.getDisplayList(View.java:13505)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.getDisplayList(View.java:13552)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.draw(View.java:14330)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.draw(View.java:14616)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.widget.FrameLayout.draw(FrameLayout.java:472)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.widget.ScrollView.draw(ScrollView.java:1603)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.getDisplayList(View.java:13510)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.getDisplayList(View.java:13552)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.draw(View.java:14330)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.getDisplayList(View.java:13505)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.getDisplayList(View.java:13552)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.draw(View.java:14330)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.getDisplayList(View.java:13505)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.getDisplayList(View.java:13552)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.draw(View.java:14330)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.getDisplayList(View.java:13505)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.getDisplayList(View.java:13552)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.draw(View.java:14330)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.draw(View.java:14616)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.getDisplayList(View.java:13510)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.getDisplayList(View.java:13552)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.draw(View.java:14330)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at com.jeremyfeinstein.slidingmenu.lib.CustomViewAbove.dispatchDraw(CustomViewAbove.java:827)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.draw(View.java:14616)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.getDisplayList(View.java:13510)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.getDisplayList(View.java:13552)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.draw(View.java:14330)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.getDisplayList(View.java:13505)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.getDisplayList(View.java:13552)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.draw(View.java:14330)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.getDisplayList(View.java:13505)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.getDisplayList(View.java:13552)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.draw(View.java:14330)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.draw(View.java:14616)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at com.android.internal.widget.ActionBarOverlayLayout.draw(ActionBarOverlayLayout.java:381)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.getDisplayList(View.java:13510)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.getDisplayList(View.java:13552)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.draw(View.java:14330)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.view.View.draw(View.java:14616)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at android.widget.FrameLayout.draw(FrameLayout.java:472)
03-16 14:17:50.890: E/AndroidRuntime(11180):    at com.android.internal.p
    
asked by anonymous 16.03.2015 / 18:06

1 answer

1

Save a copy of Bitmap so you can use it later:

Instead of:

Bitmap bitmap = view.getDrawingCache();

Make:

Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache(true));  

Source: SO.com

By what I understand the imageView is recycling "drawing cache" when you no longer need it. When making a copy you maintain a reference to Bitmap even though ImageView will destroy cache .     

16.03.2015 / 19:23