Skip to content

Instantly share code, notes, and snippets.

@vibin
Created October 8, 2014 16:49
Show Gist options
  • Save vibin/6aac5ceda47c76463d95 to your computer and use it in GitHub Desktop.
Save vibin/6aac5ceda47c76463d95 to your computer and use it in GitHub Desktop.
RequestQueue req;
ImageLoader.ImageCache imageCache;
ImageLoader imageLoader;
final int DEFAULT_CACHE_SIZE = 16 * 1024 * 1024; // for DiskBasedCache
private static final String DEFAULT_CACHE_DIR = "volley";
private void createImageLoader() {
if (imageCache == null) {
imageCache = new BitmapLruCache();
imageLoader = new ImageLoader(Volley.newRequestQueue(this), imageCache);
}
}
public ImageLoader getImageLoader() {
return imageLoader;
}
/**
* If RequestQueue is null, create one with {@code cacheSize} amount of cache
*/
public RequestQueue getRequestQueue() {
if (req == null) {
req = Volley.newRequestQueue(this);
File cacheDir = new File(this.getCacheDir(), DEFAULT_CACHE_DIR);
DiskBasedCache cache = new DiskBasedCache(cacheDir, DEFAULT_CACHE_SIZE);
req = new RequestQueue(cache, new BasicNetwork(new HurlStack()));
req.start();
}
return req;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment