exception:
java.lang.OutOfMemoryError: Failed to allocate a 1852142714 byte allocation with 8388608 free bytes and 229MB until OOM
at com.android.volley.toolbox.DiskBasedCache.streamToBytes(DiskBasedCache.java:321)
at com.android.volley.toolbox.DiskBasedCache.readString(DiskBasedCache.java:531)
at com.android.volley.toolbox.DiskBasedCache.readStringStringMap(DiskBasedCache.java:554)
at com.android.volley.toolbox.DiskBasedCache$CacheHeader.readHeader(DiskBasedCache.java:397)
at com.android.volley.toolbox.DiskBasedCache.initialize(DiskBasedCache.java:155)
at com.android.volley.CacheDispatcher.run(CacheDispatcher.java:84)
volley本来就不建议用来缓存太多的数据。遇到这种情况,目前的最好的解决方案貌似只有暴力清理缓存。
下面就贴下清理缓存的方法:
在获取请求队列的时候,拿到DiskBasedCache的引用,然后通过ClearCacheRequest来清理掉volley的缓存
private RequestQueue getRequestQueue() {if (mRequestQueue == null) {mRequestQueue = Volley.newRequestQueue(getApplicationContext());}File cacheDir = new File(this.getCacheDir(), "volley");DiskBasedCache cache = new DiskBasedCache(cacheDir);mRequestQueue.start();// clear all volley caches.mRequestQueue.add(new ClearCacheRequest(cache, null));return mRequestQueue;}
ps:volley默认的缓存放在/data/data/包名/cache/volley 下
版权声明:本文为博主原创文章,,未经博主允许不得转载。
无做什么,记得为自己而做,那就毫无怨言。