我正在研究一個具有上傳配置文件圖像功能的android應用程序。我面臨的問題是每當用戶嘗試上傳新的配置文件圖像時,它都會成功上傳到lserver,但嘗試通過排空庫加載新圖像並不反映新圖像,ImageView仍會顯示舊圖像。爲了更加清晰,我也粘貼了抽象單例類實現。Android排球圖像url緩存不清除
我試着使用下面提到的兩種方法清除緩存,但它不起作用。也嘗試通過invalidate()方法使ImageView失效,但是這也不起作用,所以看起來更像是一個android緩存問題。
如果有人遇到類似的情況,請幫助。
1)mVolleySingleton.getRequestQueue()。getCache()。invalidate(urlProfileImage,true);
2)mVolleySingleton.getRequestQueue()。getCache()。remove(urlProfileImage);
凌空Singleton類實現:
public class VolleySingleton {
private static VolleySingleton sInstance = null;
private ImageLoader mImageLoader;
private RequestQueue mRequestQueue;
private VolleySingleton() {
mRequestQueue = Volley.newRequestQueue(MainActivity.getAppContext());
mImageLoader = new ImageLoader(mRequestQueue, new ImageLoader.ImageCache() {
public LruCache<String, Bitmap> cache = new LruCache<>((int) (Runtime.getRuntime().maxMemory()/1024)/8);
@Override
public Bitmap getBitmap(String url) {
return cache.get(url);
}
@Override
public void putBitmap(String url, Bitmap bitmap) {
cache.put(url, bitmap);
}
});
}
public static VolleySingleton getInstance() {
if (sInstance == null) {
sInstance = new VolleySingleton();
}
return sInstance;
}
public RequestQueue getRequestQueue() {
return mRequestQueue;
}
public ImageLoader getImageLoader() {
return mImageLoader;
}
}
'//如果你不想使用緩存 mImageLoader =新的ImageLoader(mRequestQueue,新的ImageLoader。ImageCache(){ @Override public Bitmap getBitmap(String url){ return null; } @覆蓋 公共無效putBitmap(字符串URL,位圖位圖){} });' – BNK
即使我禁用像你建議的緩存,我仍然無法看到更新的圖像。 –