Android Studio 3.5。
我需要将异步图片加载到位图。如果加载失败,则获取例外。这里是代码段:
private Bitmap bannerImageBitmap;
Glide.with(this)
.asBitmap()
.load(imageURL)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.skipMemoryCache(false)
.addListener(new RequestListener<Bitmap>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
// do some with exception
return false;
}
@Override
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
bannerImageBitmap = resource;
onLoadSuccess();
return false;
}
}).submit();
}
这是正确的方法吗?