Android : Android: Volley does not delete cache

on Sunday, September 21, 2014


I'm have add volley for request to get Json object and cache data. but when i clear all cache, seem all data not delele. Because when i turn off my network and restart my app .It still using cache.


I do the following code


public class AppController extends Application {



public static final String TAG = AppController.class.getName();

public static AppController mIntance;

private RequestQueue requestQueue;

private ImageLoader imageLoader;

/**
* onCreate of class that is extend Application always call first when app laucher . to benefit
* create object singleton.
*
* @param err
* @param context
* @return
*/
@Override
public void onCreate() {
super.onCreate();
mIntance = this;


}


public static synchronized AppController getIntance() {

return mIntance;
}

public RequestQueue getRequestQueue() {

/*
* if (requestQueue == null) { requestQueue =
* MyRequest.newRequestQueue(getApplicationContext()); }
*/

if (requestQueue == null) {
requestQueue = Volley.newRequestQueue(getApplicationContext());
}

return requestQueue;
}


public <T> void addToRequestQueue(Request<T> req, String tag) {

// hoa ra settag la cho req nay ,. minh cu tuong no set cho c�i
// requestqueue

req.setTag(tag.equals("") ? TAG : tag);
getRequestQueue().add(req);

}

// using request with string default
public <T> void addToRequestQueue(Request<T> req) {
req.setTag(TAG);
getRequestQueue().add(req);
}


public void cancelRequest(Object tag) {
if (requestQueue != null) {
requestQueue.cancelAll(tag);

}

}

public void cancelAllRequest() {
if (requestQueue != null) {
requestQueue.cancelAll("feed_request");

}

}

/*
* clear some cache
*/

public void DeletelCacheFromSomeURL(ArrayList<String> array) {
for (int i = 0; i < array.size(); i++) {
requestQueue.getCache().remove(array.get(i));
}

}


}


i have clear all cache flowing



AppController.getIntance().getRequestQueue().getCache()
.clear();


Anyone explain and give me solution . thank !


0 comments:

Post a Comment