E/MainActivity: executeTextView: testfor get drawable: last source: android.graphics.drawable.BitmapDrawable@8c352b2 executeTextView: testfor get drawable: isVisible true alpha: 255 last source: android.graphics.drawable.BitmapDrawable@8c352b2 W/Bitmap: Called hasAlpha() on a recycle()'d bitmap! This is undefined behavior! Called hasAlpha() on a recycle()'d bitmap! This is undefined behavior! Called hasAlpha() on a recycle()'d bitmap! This is undefined behavior! W/Bitmap: Called hasAlpha() on a recycle()'d bitmap! This is undefined behavior! E/MainActivity: Glide结束 executeImageView: ... E/MainActivity: showQrCode: 举报二维码1: showQrCode: 举报二维码2: https://xxx.com/upload/equipmentWxQRCode/15776698271ada7952f9ead4d5.jpg D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main Process: com.rootrl.adviewer, PID: 29128 java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@ac257b9 at android.graphics.Canvas.throwIfCannotDraw(Canvas.java:1271) at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:257) at android.graphics.Canvas.drawBitmap(Canvas.java:1415) at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:528) at android.widget.ImageView.onDraw(ImageView.java:1298) at android.view.View.draw(View.java:17201) at android.view.View.updateDisplayListIfDirty(View.java:16183) at android.view.View.draw(View.java:16967) at android.view.ViewGroup.drawChild(ViewGroup.java:3727) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513) at androidx.constraintlayout.widget.ConstraintLayout.dispatchDraw(ConstraintLayout.java:2023) at android.view.View.updateDisplayListIfDirty(View.java:16178) at android.view.View.draw(View.java:16967) at android.view.ViewGroup.drawChild(ViewGroup.java:3727) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513) at androidx.constraintlayout.widget.ConstraintLayout.dispatchDraw(ConstraintLayout.java:2023) at android.view.View.draw(View.java:17204) at android.view.View.updateDisplayListIfDirty(View.java:16183) at android.view.View.draw(View.java:16967) at android.view.ViewGroup.drawChild(ViewGroup.java:3727) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513) at android.view.View.updateDisplayListIfDirty(View.java:16178) at android.view.View.draw(View.java:16967) at android.view.ViewGroup.drawChild(ViewGroup.java:3727) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513) at android.view.View.updateDisplayListIfDirty(View.java:16178) at android.view.View.draw(View.java:16967) at android.view.ViewGroup.drawChild(ViewGroup.java:3727) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513) at android.view.View.updateDisplayListIfDirty(View.java:16178) at android.view.View.draw(View.java:16967) at android.view.ViewGroup.drawChild(ViewGroup.java:3727) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513) at android.view.View.updateDisplayListIfDirty(View.java:16178) at android.view.View.draw(View.java:16967) at android.view.ViewGroup.drawChild(ViewGroup.java:3727) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513) at android.view.View.draw(View.java:17204) at com.android.internal.policy.DecorView.draw(DecorView.java:754) at android.view.View.updateDisplayListIfDirty(View.java:16183) at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:648) at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:654) at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:762) at android.view.ViewRootImpl.draw(ViewRootImpl.java:2800) at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2608) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2215) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1254) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6338) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:874) at android.view.Choreographer.doCallbacks(Choreographer.java:686) at android.view.Choreographer.doFrame(Choreographer.java:621) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:860) at android.os.Handler.handleCallback(Handler.java:755) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6121) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795) I/Process: Sending signal. PID: 29128 SIG: 9 Process 29128 terminated.
Glide’s BitmapPool has a fixed size. When Bitmaps are evicted from the pool without being re-used, Glide will call recycle(). If an application inadvertently continues to hold on to the Bitmap even after indicating to Glide that it is safe to recycle it, the application may then attempt to draw the Bitmap, resulting in a crash in onDraw(). This problem could be due to the fact that one target is being used for two ImageViews, and one of the ImageViews still tries to access the recycled Bitmap after it has been put into the BitmapPool. This recycling error can be hard to reproduce, due to several factors: 1) when the bitmap is put into the pool, 2) when the bitmap is recycled, and 3) what the size of the BitmapPool and memory cache are that leads to the recycling of the Bitmap. The following snippet can be put into your GlideModule to help making this problem easier to reproduce: @Override publicvoidapplyOptions(Context context, GlideBuilder builder){ int bitmapPoolSizeBytes = 1024 * 1024 * 0; // 0mb int memoryCacheSizeBytes = 1024 * 1024 * 0; // 0mb builder.setMemoryCache(new LruResourceCache(memoryCacheSizeBytes)); builder.setBitmapPool(new LruBitmapPool(bitmapPoolSizeBytes)); } The above code makes sure that there is no memory caching and the size of the BitmapPool is zero; so Bitmap, if happened to be not used, will be recycled right away. The problem will surface much quicker for debugging purposes.