android - 如何使用通用图像加载器在 Intent 服务(后台线程)中缓存图像

标签 android caching universal-image-loader

我正在测试升级以使用 Android Universal Image Loader 1.9.0。我已经在 Android 4.2 上测试过了。我遇到了一个问题,我在 Intent 服务中下载和缓存图像以在后台线程上运行以不干扰用户。但是,UIL 提示我没有在主线程上加载这些图像。我不想在主线程上加载这些图像,我只是希望能够在后台将它们缓存在磁盘上,以便用户实际查看指定图像时不需要下载它们。除了 ImageLoader.loadImage 之外,还有其他方法可以在后台线程上预缓存图像吗?如果不是,我如何允许在非主线程的线程上在光盘上进行预缓存?所有这些代码都在 IntentService 中运行。

图像加载器配置:

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
            getApplicationContext())
            .threadPriority(Thread.MAX_PRIORITY)
            .memoryCacheSize(memoryCacheSize)
            .denyCacheImageMultipleSizesInMemory()
            .threadPoolSize(5)
            .discCacheFileNameGenerator(new MyFileNameGenerator())
            .tasksProcessingOrder(QueueProcessingType.LIFO)
            .build();

显示图像选项:

 DisplayImageOptions options = new DisplayImageOptions.Builder().cacheOnDisc()
                .imageScaleType(ImageScaleType.NONE).build();

加载图片代码:

imageLoader.loadImage(imageURI, options,
            new SimpleImageLoadingListener() {
                @Override
                public void onLoadingComplete(String imageUri, View view,
                        Bitmap loadedImage)
                {
                    loadNext();  // gives a notification update and loads next image URI in queue
                }

                @Override
                public void onLoadingFailed(String imageUri, View view,
                        FailReason failReason)
                {
                    loadNext(); // gives a notification update and loads next image URI in queue
                }
            });

最佳答案

实际上 UIL 不提供预加载图像的方法,即只是添加到磁盘缓存。它总是返回解码后的位图。

但在您的情况下,您可以使用 loadImageSync(...)。我认为它更适合你。

关于android - 如何使用通用图像加载器在 Intent 服务(后台线程)中缓存图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20504477/

相关文章:

android - 通用图像加载器

android - 使用支持库时出现错误,指出属性 ""已在 android 中定义

android - Android下OpenGLES 2.0基于像素的碰撞检测问题

c# - 使用 ASP.NET、C# 和 Winnovative.WnvHtmlConvert.PdfConverter 重新创建新的 PDF 仍保留旧图像

caching - Spark 缓存是否会以任何时间间隔自动更新数据的新值?

android - ImageView 加载高分辨率图像质量很差

android - 如何隐藏 Android sdkmanager 下载进度条?

java - 将此 Activity 转换为 fragment

css - 包含两个具有相同 ID 的 Html 元素的页面将如何影响 Google 索引?

android - UIL,Picasso - 适配器中的图像总是在停止滚动时重新加载