gpt4 book ai didi

android - 使用 Glide 库时崩溃

转载 作者:行者123 更新时间:2023-12-03 16:44:44 29 4
gpt4 key购买 nike

使用 Glide 库将不同大小的图像加载到 ImageView 中。但不确定为什么 glide 无法处理内存消耗、回收和重用它。

Gradle :

api 'com.github.bumptech.glide:glide:4.3.0'

用法:

@BindingAdapter({"imageUrl"})
public static void imageUrl(ImageView view, String imageUrl) {
try {
if (imageUrl!=null) {
Glide.with(view.getContext()).load(imageUrl).into(view);
}
} catch (Exception e) {
e.printStackTrace();
}
}

崩溃日志:
 04-23 13:19:34.390 4758-4758/xx.xx.xxxE/AndroidRuntime: FATAL EXCEPTION: main
Process: xxx.xx.xxxx, PID: 4758
java.lang.RuntimeException: Unable to destroy activity {xx.xx.xx/x.xx.xx.xxx.xxxxActivity}: java.lang.IllegalStateException: Cannot obtain size for recycled Bitmap: android.graphics.Bitmap@e212eb2[12x12] ARGB_8888
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4603)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4621)
at android.app.ActivityThread.-wrap5(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1757)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: java.lang.IllegalStateException: Cannot obtain size for recycled Bitmap: android.graphics.Bitmap@e212eb2[12x12] ARGB_8888
at com.bumptech.glide.util.Util.getBitmapByteSize(Util.java:74)
at com.bumptech.glide.load.engine.bitmap_recycle.SizeConfigStrategy.removeLast(SizeConfigStrategy.java:97)
at com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool.trimToSize(LruBitmapPool.java:221)
at com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool.evict(LruBitmapPool.java:116)
at com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool.put(LruBitmapPool.java:112)
at com.bumptech.glide.load.resource.bitmap.LazyBitmapDrawableResource.recycle(LazyBitmapDrawableResource.java:57)
at com.bumptech.glide.load.engine.EngineResource.recycle(EngineResource.java:63)
at com.bumptech.glide.load.engine.ResourceRecycler.recycle(ResourceRecycler.java:28)
at com.bumptech.glide.load.engine.Engine.onResourceRemoved(Engine.java:326)
at com.bumptech.glide.load.engine.cache.LruResourceCache.onItemEvicted(LruResourceCache.java:31)
at com.bumptech.glide.load.engine.cache.LruResourceCache.onItemEvicted(LruResourceCache.java:11)
at com.bumptech.glide.util.LruCache.trimToSize(LruCache.java:175)
at com.bumptech.glide.util.LruCache.evict(LruCache.java:180)
at com.bumptech.glide.util.LruCache.put(LruCache.java:135)
at com.bumptech.glide.load.engine.cache.LruResourceCache.put(LruResourceCache.java:11)
at com.bumptech.glide.load.engine.Engine.onResourceReleased(Engine.java:334)
at com.bumptech.glide.load.engine.EngineResource.release(EngineResource.java:101)
at com.bumptech.glide.load.engine.Engine.release(Engine.java:292)
at com.bumptech.glide.request.SingleRequest.releaseResource(SingleRequest.java:337)
at com.bumptech.glide.request.SingleRequest.clear(SingleRequest.java:316)
at com.bumptech.glide.manager.RequestTracker.clearRemoveAndRecycle(RequestTracker.java:62)
at com.bumptech.glide.RequestManager.untrack(RequestManager.java:462)
at com.bumptech.glide.RequestManager.untrackOrDelegate(RequestManager.java:449)
at com.bumptech.glide.RequestManager.clear(RequestManager.java:437)
at com.bumptech.glide.RequestManager.onDestroy(RequestManager.java:290)
at com.bumptech.glide.manager.ActivityFragmentLifecycle.onDestroy(ActivityFragmentLifecycle.java:64)
at com.bumptech.glide.manager.SupportRequestManagerFragment.onDestroy(SupportRequestManagerFragment.java:187)
at android.support.v4.app.Fragment.performDestroy(Fragment.java:2516)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1557)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1750)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1819)
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3227)
at android.support.v4.app.FragmentManagerImpl.dispatchDestroy(FragmentManager.java:3218)
at android.support.v4.app.FragmentController.dispatchDestroy(FragmentController.java:262)
04-23 13:19:34.391 4758-4758/xx.xxx.xxxE/AndroidRuntime: at android.support.v4.app.FragmentActivity.onDestroy(FragmentActivity.java:362)
at android.support.v7.app.AppCompatActivity.onDestroy(AppCompatActivity.java:209)
at android.app.Activity.performDestroy(Activity.java:7462)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1255)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4590)
... 9 more

*使用“xxx”作为包名忽略它。

最佳答案

试试 RequestOptions & 升级版本。

RequestOptions requestOptions = new RequestOptions();
Glide.with(getContext())
.setDefaultRequestOptions(requestOptions)
.load(imageUrl)
.into(view);

build.gradle 应该
 dependencies {
implementation 'com.github.bumptech.glide:glide:4.6.1'
}

您可以阅读 Cannot obtain size for recycled Bitmap (LazyBitmapDrawableResource) .

关于android - 使用 Glide 库时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49976044/

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