【发布时间】:2014-01-29 14:23:30
【问题描述】:
我在应用程序中有很多在 volley 中完成的字符串请求。在每个模块中,都有一个不同的 onResponseListener 总是做不同的事情。而且我需要让它们也离线工作。所以我从缓存中得到响应。问题是可能会有很多使用不同 url 异步调用的请求。问题是从缓存中获取请求时如何记住请求的 url。目前它只在全局变量中,但由于请求可以异步发送,响应可能与全局变量 url 不匹配。有什么方法可以在 onResponse 中获取这个请求的原始请求 url 并直接在 Application.get().getApi().getCache(url) 中使用它?
请求看起来总是这样:
Application.get().getApi().getRequest(url, mListener);
mListener:
private class ResponseListenerX extends Api.ResponseListener {
@Override
public void onResponse(String response) {
if (response != null) {
}
}
@Override
public void onErrorResponse(VolleyError error) {
if ((error == null || error.networkResponse == null) && url != null) {
// how to get here url from the request
String response = Application.get().getApi().getCache(url);
if (response != null && response.length() > 0) {
// onResponse
}
}
}
}
【问题讨论】:
标签: android caching asynchronous android-volley