无法用Gllide替换Universal Image Loader功能

时间:2017-06-22 06:11:48

标签: java android multithreading android-glide

Universal Image Loader有一些方法可以在主线程上加载图像,但Glide总是在其他线程上加载图像。 使用通用库时,我可以通过缓存直接获取Drawable,但在Glide中我正在这样做,

public Drawable fun(){
Drawable blurredImage=null;
RequestOptions options=new RequestOptions();
                options.onlyRetrieveFromCache(true);

                Glide.with(mContext).load(url).apply(options).into(new SimpleTarget<Drawable>() {
                    @Override
                    public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
                        blurredImage=resource;
                    }

                    @Override
                    public void onLoadFailed(@Nullable Drawable errorDrawable) {
                        blurredImage=null;
                    }
                });
return blurredImage;
}

现在,这个函数总是返回null,因为Glide正在处理其他线程,并且会调用OnResourceReady一些滞后。 我想在调用return语句之前等待函数初始化blurImage; 我想在这里使用wait(),notify(),但无法理解如何。

0 个答案:

没有答案