ERRO; Canvas: trying to use a Recycled bitmap android.graphics.Bitmap

Asked

Viewed 281 times

1

Guys I’m taking a bitmap of a gridview and displaying in another Activity, then when I open 3x the other Activity the app hangs and closes.

First action

view.buildDrawingCache();

                    Bitmap bitmap = view.getDrawingCache();

Second

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

You can help me with that?

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
  • Let me guess, OutOfMemory? More details of the error that is occurring. Post the output in the stack trace.

  • I’ve already asked the question

1 answer

1


Keep a copy of Bitmap so that it can be used later:

Instead of:

Bitmap bitmap = view.getDrawingCache();

Do:

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

Source: SO AS.

For what I understood the imageView is recycling the "Drawing cache" when you no longer need it. When making a copy you keep a reference to Bitmap even if the Imageview destroy the cache.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.