[android-developers] RuntimeException: Canvas: trying to use a recycled bitmap
Hi! I'm having a weird problem with one of my apps. I'll try later to extract some code and make a sample project to share if it's useful but by now I'm just asking to see if anyone found this one or can give me a hint on how to tackle it. I have two activities. Activity A extends SherlockActivity from ActionBarSherlock and haves a GridView on it. The grid items have an ImageButton. When you press on the ImageButton, it calls an instance of Activity B. Activity B extends SherlockFragmentActivity (ActionBarSherlock again), with a ViewPager on it. The fragments have a very complex layout. My Activity B has a menu with only one item. The item is set-up on onOptionsItemSelected so it simply calls onBackPressed(). That one calls super.onBackPressed() right away. I've only overridden it for debugging purposes. I tested it on some Jelly Bean devices and on a couple Gingerbread ones (I'm using some co-workers phones as test devices :)). On Jelly Bean it's ok. But in Gingerbread I've met a weird behaviour. When I'm on B, and press the back button on the device, it closes B and goes normally to A. But, if I press the option on the menu, I've got a force close message and I've got the following log: java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@2b021388 at android.graphics.Canvas.throwIfRecycled(Canvas.java:955) at android.graphics.Canvas.drawBitmap(Canvas.java:1044) at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:325) at android.widget.ImageView.onDraw(ImageView.java:881) at android.view.View.draw(View.java:6986) at android.view.ViewGroup.drawChild(ViewGroup.java:1739) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466) at android.view.ViewGroup.drawChild(ViewGroup.java:1737) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466) at android.view.View.draw(View.java:6989) at android.widget.FrameLayout.draw(FrameLayout.java:361) at android.view.ViewGroup.drawChild(ViewGroup.java:1739) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466) at android.view.View.draw(View.java:6989) at android.widget.FrameLayout.draw(FrameLayout.java:361) at android.view.ViewGroup.drawChild(ViewGroup.java:1739) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466) at android.view.ViewGroup.drawChild(ViewGroup.java:1737) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466) at android.view.View.draw(View.java:6989) at android.support.v4.view.ViewPager.draw(ViewPager.java:1923) at android.view.ViewGroup.drawChild(ViewGroup.java:1739) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466) at android.view.ViewGroup.drawChild(ViewGroup.java:1737) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466) at android.view.ViewGroup.drawChild(ViewGroup.java:1737) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466) at android.view.ViewGroup.drawChild(ViewGroup.java:1737) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466) at android.view.ViewGroup.drawChild(ViewGroup.java:1737) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466) at android.view.View.draw(View.java:6989) at android.widget.FrameLayout.draw(FrameLayout.java:361) at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1882) at android.view.ViewRoot.draw(ViewRoot.java:1544) at android.view.ViewRoot.performTraversals(ViewRoot.java:1280) at android.view.ViewRoot.handleMessage(ViewRoot.java:1882) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:130) at android.app.ActivityThread.main(ActivityThread.java:3701) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624) at dalvik.system.NativeStart.main(Native Method) The stack seems to relate to my Activity B structure. My app loads puts large images on screen, so I have a couple recycle() calls on the fragments that take part of Activity B, but they're all inside !bitmap.isRecycled() conditions, and they're all around the first steps on the activity and fragments life cycle. Anyway, there is no recycle() call in my whole project that it's not followed by some assignation, either with null or with some generated bitmap. When I debugged the exception didn't fire there. It just appears to be nowhere, jumping outright from the last line on my onPause() on Activity B to the runtime exception. To add some debug chance, I've set a handler with setDefaultUncaughtExceptionHandler to check what the behaviour would be after the Exception is thrown, and what I see is: * In a Samsung device with a Mod Gingerbreas, first the option on the menu on Activity B disappearing, then the Activity B dissapearing into to background, a black screen and just a couple seconds later I get an ANR. * In an unrooted Sony device , I've got to the
[android-developers] RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.bit...@43895170
Hi, I am getting the following logs when i am changing the wallpaper for Homescreen. Even i am recycling the bitmap is done when the wallpaper changes in OnWallpaperChanged(). Still i m getting the bellow error. 03-26 05:02:16.829: INFO/AC(1340): setWallpaper(InputStream 03-26 05:02:16.840: INFO/AC(1340): setWallpaper(InputStream, FileOutputStream) 03-26 05:02:16.889: INFO/WallpaperService(1059): Wallpaper is changed!!! 03-26 05:02:16.899: INFO/WallpaperService(1059): beginBroadcast()2 03-26 05:02:16.899: INFO/ApplicationContext(1694): com.lge.homecube 03-26 05:02:16.899: INFO/ApplicationContext(1694): applicationContext is not null 03-26 05:02:16.899: INFO/ApplicationContext(1694): make mWallpaper null 03-26 05:02:16.909: INFO/WallpaperService(1059): onWallpaperChanged0 03-26 05:02:16.909: INFO/WallpaperService(1059): notifyCallbacks() 03-26 05:02:16.909: INFO/ApplicationContext(1059): android 03-26 05:02:16.909: INFO/ApplicationContext(1059): applicationContext is not null 03-26 05:02:16.909: INFO/ApplicationContext(1059): make mWallpaper null 03-26 05:02:16.909: INFO/WallpaperService(1059): onWallpaperChanged1 03-26 05:02:16.909: INFO/WallpaperService(1059): notifyCallbacks() 03-26 05:02:16.989: WARN/dalvikvm(1694): threadid=3: thread exiting with uncaught exception (group=0x40013e70) 03-26 05:02:16.989: ERROR/AndroidRuntime(1694): Uncaught handler: thread main exiting due to uncaught exception 03-26 05:02:17.019: WARN/LockPatternKeyguardView(1059): LockpatternKeyguardView WallpaperIntentReceiver_getWallpaper start 03-26 05:02:17.019: INFO/ApplicationContext(1059): getWallpaper() 03-26 05:02:17.029: INFO/ApplicationContext(1059): android 03-26 05:02:17.029: INFO/ApplicationContext(1059): GetCurrentWallaper 03-26 05:02:17.029: INFO/ApplicationContext(1059): Normal image wallpaper 03-26 05:02:17.029: INFO/WallpaperService(1059): List Of Callbacks 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.bit...@43895170 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at android.graphics.Canvas.throwIfRecycled(Canvas.java:942) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at android.graphics.Canvas.drawBitmap(Canvas.java:962) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at com.lge.homecube.Workspace.dispatchDraw(Workspace.java:596) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at android.view.ViewGroup.drawChild(ViewGroup.java:1484) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at com.lge.homecube.DragLayer.dispatchDraw(DragLayer.java:280) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at android.view.ViewGroup.drawChild(ViewGroup.java:1484) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at android.view.View.draw(View.java:5862) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at android.widget.FrameLayout.draw(FrameLayout.java:352) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at android.view.ViewGroup.drawChild(ViewGroup.java:1486) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at android.view.View.draw(View.java:5862) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at android.widget.FrameLayout.draw(FrameLayout.java:352) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw (PhoneWindow.java:1892) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at android.view.ViewRoot.draw(ViewRoot.java:1239) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at android.view.ViewRoot.performTraversals(ViewRoot.java:1049) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at android.view.ViewRoot.handleMessage(ViewRoot.java:1507) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at android.os.Handler.dispatchMessage(Handler.java:99) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at android.os.Looper.loop(Looper.java:123) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at android.app.ActivityThread.main(ActivityThread.java:3948) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at java.lang.reflect.Method.invokeNative(Native Method) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at java.lang.reflect.Method.invoke(Method.java:521) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:782) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540) 03-26 05:02:17.079: ERROR/AndroidRuntime(1694): at dalvik.system.NativeStart.main(Native Method) 03-26 05:02:17.269: INFO/ApplicationContext(1059): Read wallpaper file. 03-26 05:02:17.629: