Search code examples
androidcachinguniversal-image-loader

Universal Image Loader cache images


I have trouble finding the right workflow to load images into cache.

What I want to do:

  • Show Progress bar
  • Get data from REST service and load it into SQLite database
  • Some objects contain urls in JSON > load these images in cache so they are quickly loaded when needed
  • Dismiss Progress bar

I have all the data loaded from rest and stored in a DB, but I'm new to caching images.

What I go so far: - Inserted Universal Image Loader into my project (https://github.com/nostra13/Android-Universal-Image-Loader) - I tried

imageLoader.loadImage(url of an image, new SimpleImageLoadingListener() {

                    @Override
                    public void onLoadingStarted(String imageUri, View view) {
                        super.onLoadingStarted(imageUri, view);
                        //notify me the image started loading
                    }

                    @Override
                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                        super.onLoadingComplete(imageUri, view, loadedImage);
                        //notify me the image is loaded
                    }
}

But when I check:

int size = MemoryCacheUtils.findCachedBitmapsForImageUri(url from that image, ImageLoader.getInstance().getMemoryCache()).size();
             //show me the size

it's always zero.

My question is the following: am I going in the right direction or do I need to fix this someother way?


Solution

  • I found a better solution: ShutterBug (Android alternative for SDWebImage for iOs). It's easy to add urls to the ShutterbugManager and when I want to fill an ImageView (FetchableImageView in Shutterbug) with an image, it grabs the image from cache.