You first need to detach those bitmaps from their views (calling setImageDrawable(null) on ImageView for instance.)
On Fri, Aug 3, 2012 at 2:54 PM, Tolriq <[email protected]> wrote: > This sounds logical but since it worked on all release before JB I was > supposing that doing this in OnStop() would be done after view unload. > > What is the correct way to recycle bitmaps loaded in AbsListView ? > > Le vendredi 3 août 2012 23:45:35 UTC+2, Romain Guy (Google) a écrit : >> >> You cannot recycle bitmaps of Views that are still attached to the window. >> >> On Fri, Aug 3, 2012 at 2:40 PM, Tolriq wrote: >> > Hello, >> > >> > I have an app that works ok from 2.2 to 4.0 since 4.1 I started to have >> > "java.lang.IllegalArgumentException: Cannot draw recycled bitmaps". >> > After some optimizations and tests, i finally find that for an unknown >> > reason android wants to refresh my listview after the onstop during >> > screen >> > off event on some devices. >> > >> > The activity is a not so complex listview with lazy loading of images. >> > >> > To optimize memory in the onstop of my listview activity i recycle >> > bitmaps >> > with a simple : (needed since there lot's of activity like this one and >> > on >> > some devices bitmaps are not garbaged quickly enough). >> >> >> >> final AbsListView listView = (AbsListView) >> >> findViewById(R.id.mediaslist_list); >> >> int c = listView.getChildCount(); >> >> for (int i = 0; i < c; i++) { >> >> adapter.recycleView(listView.getChildAt(i)); >> >> } >> > >> > >> > in the OnStop(); where the recycleView just recycle the bitmap. >> > >> > In Nexus 7 or emulator in landscape, when i shutdown screen the onstop >> > is >> > called but since it wants to go to portrait for lock-screen it does >> > something with the listview and try to redraw it. >> > Leading to the error : >> > >> >> java.lang.IllegalArgumentException: Cannot draw recycled bitmaps >> >> at android.view.GLES20Canvas.drawBitmap(GLES20Canvas.java:778) >> >> at >> >> >> >> android.view.GLES20RecordingCanvas.drawBitmap(GLES20RecordingCanvas.java:117) >> >> at >> >> android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:393) >> >> at android.widget.ImageView.onDraw(ImageView.java:979) >> >> at android.view.View.draw(View.java:13458) >> >> at android.view.View.getDisplayList(View.java:12409) >> >> at android.view.View.getDisplayList(View.java:12453) >> >> at android.view.View.draw(View.java:13182) >> >> at android.view.ViewGroup.drawChild(ViewGroup.java:2929) >> >> at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799) >> >> at android.view.View.draw(View.java:13461) >> >> at android.view.View.getDisplayList(View.java:12409) >> >> at android.view.View.getDisplayList(View.java:12453) >> >> at android.view.View.draw(View.java:13182) >> >> at android.view.ViewGroup.drawChild(ViewGroup.java:2929) >> >> at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799) >> >> at android.widget.AbsListView.dispatchDraw(AbsListView.java:2433) >> >> at android.view.View.draw(View.java:13461) >> >> at android.widget.AbsListView.draw(AbsListView.java:3759) >> >> at android.view.View.getDisplayList(View.java:12409) >> >> at android.view.View.getDisplayList(View.java:12453) >> >> at android.view.View.draw(View.java:13182) >> >> at android.view.ViewGroup.drawChild(ViewGroup.java:2929) >> >> at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799) >> >> at android.view.View.getDisplayList(View.java:12407) >> >> at android.view.View.getDisplayList(View.java:12453) >> >> at android.view.View.draw(View.java:13182) >> >> at android.view.ViewGroup.drawChild(ViewGroup.java:2929) >> >> at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799) >> >> at android.view.View.getDisplayList(View.java:12407) >> >> at android.view.View.getDisplayList(View.java:12453) >> >> at android.view.View.draw(View.java:13182) >> >> at android.view.ViewGroup.drawChild(ViewGroup.java:2929) >> >> at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799) >> >> at android.view.View.getDisplayList(View.java:12407) >> >> at android.view.View.getDisplayList(View.java:12453) >> >> at android.view.View.draw(View.java:13182) >> >> at android.view.ViewGroup.drawChild(ViewGroup.java:2929) >> >> at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799) >> >> at android.view.View.draw(View.java:13461) >> >> at android.widget.FrameLayout.draw(FrameLayout.java:467) >> >> at >> >> >> >> com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2183) >> >> at android.view.View.getDisplayList(View.java:12409) >> >> at android.view.View.getDisplayList(View.java:12453) >> >> at >> >> >> >> android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1144) >> >> at android.view.ViewRootImpl.draw(ViewRootImpl.java:2147) >> >> at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2019) >> >> at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1830) >> >> at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998) >> >> at >> >> android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212) >> >> at >> >> android.view.Choreographer$CallbackRecord.run(Choreographer.java:725) >> >> at android.view.Choreographer.doCallbacks(Choreographer.java:555) >> >> at android.view.Choreographer.doFrame(Choreographer.java:525) >> >> at >> >> >> >> android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711) >> >> at android.os.Handler.handleCallback(Handler.java:615) >> >> at android.os.Handler.dispatchMessage(Handler.java:92) >> >> at android.os.Looper.loop(Looper.java:137) >> >> at android.app.ActivityThread.main(ActivityThread.java:4745) >> >> at java.lang.reflect.Method.invokeNative(Native Method) >> >> at java.lang.reflect.Method.invoke(Method.java:511) >> >> at >> >> >> >> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) >> >> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) >> >> at dalvik.system.NativeStart.main(Native Method) >> > >> > >> > Is there something I missed in activity lifecycle or listview one ? >> > (like >> > bitmap references saved with instancestate since JB ?) >> > >> > The app works perfect when orientation changes, just this specific case >> > gives this specific result . And on screen unlock the activity is >> > restarted >> > so the crash is half handled by the OS. >> > The problem is that I use ACRA lib so users gets notifications about >> > this >> > crash even if it's not really blocking due to activity restart. >> > >> > Regards, >> > Tolriq. >> > >> > >> > >> > >> > >> > -- >> > You received this message because you are subscribed to the Google >> > Groups "Android Developers" group. >> > To post to this group, send email to [email protected] >> > To unsubscribe from this group, send email to >> > [email protected] >> > For more options, visit this group at >> > http://groups.google.com/group/android-developers?hl=en >> >> >> >> -- >> Romain Guy >> Android framework engineer >> [email protected] > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- Romain Guy Android framework engineer [email protected] -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

