I am testing upgrading to use Android Universal Image Loader 1.9.0. I have tested this on Android 4.2. I've come across a problem where I am downloading and caching images in an intent service to be run on a background thread to not interfere with the user. However, UIL is complaining that I am not loading these images on the main thread. I don't want to load these images on the main thread, I just want to be able to cache them on disc in the background so that they don't need to be downloaded when the user actually views the specified images. Is there another way to pre-cache the images on a background thread besides ImageLoader.loadImage? If not, how do I allow pre-caching on disc on a thread that isn't the main thread? All of this code is being run in an IntentService.
ImageLoaderConfiguration:
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
getApplicationContext())
.threadPriority(Thread.MAX_PRIORITY)
.memoryCacheSize(memoryCacheSize)
.denyCacheImageMultipleSizesInMemory()
.threadPoolSize(5)
.discCacheFileNameGenerator(new MyFileNameGenerator())
.tasksProcessingOrder(QueueProcessingType.LIFO)
.build();
DisplayImageOptions:
DisplayImageOptions options = new DisplayImageOptions.Builder().cacheOnDisc()
.imageScaleType(ImageScaleType.NONE).build();
Load image code:
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
}
});
Actually UIL doesn't provide methods for preloading images, i.e. just to add to disc cache. It always returns decoded Bitmap.
But in your case you can use loadImageSync(...)
. I think it's more appropriate for you.