我试图在我的ImageLoader的缓存上调用.evictAll(),我无法弄清楚如何访问该方法
private VolleySingleton(){
mRequestQueue = Volley.newRequestQueue(VolleyApplication.getAppContext());
mImageLoader = new ImageLoader(this.mRequestQueue, new ImageLoader.ImageCache() {
private final LruCache<String, Bitmap> mCache = new LruCache<String, Bitmap>(10);
public void flushLruCache(){ mCache.evictAll();};
public void putBitmap(String url, Bitmap bitmap) {
mCache.put(url, bitmap);
}
public Bitmap getBitmap(String url) {
return mCache.get(url);
}
});
}
mRequestQueue = VolleySingleton.getInstance().getRequestQueue();
mImageLoader = VolleySingleton.getInstance().getImageLoader();
我已尝试投射我的mImageLoader对象
((ImageLoader.ImageCache) mImageLoader).flushLruCache();
但是这引发了一个错误,说我无法投射这些类型。
如何访问.flushLruCache()
方法?
答案 0 :(得分:2)
如果我没有误解,你可以在班上继续引用ImageLoader.ImageCache
private ImageLoader.ImageCache mImageCache;
private VolleySingleton(){
mRequestQueue = Volley.newRequestQueue(VolleyApplication.getAppContext());
mImageLoader = new ImageLoader(this.mRequestQueue, mImageCache = new ImageLoader.ImageCache() {
private final LruCache<String, Bitmap> mCache = new LruCache<String, Bitmap>(10);
public void flushLruCache(){ mCache.evictAll();};
public void putBitmap(String url, Bitmap bitmap) {
mCache.put(url, bitmap);
}
public Bitmap getBitmap(String url) {
return mCache.get(url);
}
});
}
并在其中声明一个evictAllImages
public void evictAllImages() {
if (mImageCache != null) {
mImageCache.flushLruCache();
}
}