gpt4 book ai didi

android - 尝试使用回收位图 android.graphics.Bitmap

转载 作者:太空宇宙 更新时间:2023-11-03 11:35:18 27 4
gpt4 key购买 nike

我在我的 activity A 中显示一个 .gif。当用户按下一个按钮时,用户移动到 activity b 并且那里显示相同的 .gif 但我收到“尝试使用回收位图 android.graphics.Bitmap”这个错误在我的 activity b 上。

我正在显示来自 SD 卡和 onStop() 的 .gif 我正在将 activity aimageview 设置为 null 以及 activity A 但我无法解决此问题。

请在这种情况下提供帮助。

//日志猫

12-31 10:58:49.819: E/AndroidRuntime(20903): java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@405131c8
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.graphics.Canvas.throwIfRecycled(Canvas.java:955)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.graphics.Canvas.drawBitmap(Canvas.java:1044)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:325)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.widget.ImageView.onDraw(ImageView.java:854)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.view.View.draw(View.java:6880)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.view.View.draw(View.java:6883)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.view.View.draw(View.java:6883)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.widget.FrameLayout.draw(FrameLayout.java:357)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.view.View.draw(View.java:6883)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.widget.FrameLayout.draw(FrameLayout.java:357)
12-31 10:58:49.819: E/AndroidRuntime(20903): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1871)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.view.ViewRoot.draw(ViewRoot.java:1542)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.view.ViewRoot.performTraversals(ViewRoot.java:1269)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.view.ViewRoot.handleMessage(ViewRoot.java:1883)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.os.Handler.dispatchMessage(Handler.java:99)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.os.Looper.loop(Looper.java:130)
12-31 10:58:49.819: E/AndroidRuntime(20903): at android.app.ActivityThread.main(ActivityThread.java:3737)
12-31 10:58:49.819: E/AndroidRuntime(20903): at java.lang.reflect.Method.invokeNative(Native Method)
12-31 10:58:49.819: E/AndroidRuntime(20903): at java.lang.reflect.Method.invoke(Method.java:507)
12-31 10:58:49.819: E/AndroidRuntime(20903): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:894)
12-31 10:58:49.819: E/AndroidRuntime(20903): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
12-31 10:58:49.819: E/AndroidRuntime(20903): at dalvik.system.NativeStart.main(Native Method)

最佳答案

您可以在回收位图之前进行检查,例如:

if (img != null && !img.isRecycled()) 
{
img.recycle();
img = null;
System.gc();
}

这里的img是位图。 尝试解决此类型错误。

关于android - 尝试使用回收位图 android.graphics.Bitmap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14136026/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com