Tengo una aplicación para Android que llama a los servicios web utilizando voleo. Si se está abriendo mi aplicación y cambiar manualmente el tiempo (hacia atrás o hacia delante), voleo no está activando nuevas solicitudes y la respuesta que ya está en la memoria caché está regresando. Si caché y los datos clara, sólo entonces la nueva solicitud se disparará y aparecerá nueva respuesta. ¿Cómo las solicitudes Volley están relacionados con la hora del sistema y por qué ocurre esto? ¿Hay alguna solución para esto?
StringRequest stringRequest = new StringRequest(Request.Method.POST, new ServiceUtils().url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// Log.d(TAG, "onResponse: response " + response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//Log.d(TAG, "onErrorResponse: " + error);
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
HashMap<String, String> nameValuePairs = new HashMap<String, String>();
nameValuePairs.put("parm1", parm1);
nameValuePairs.put("parm2", parm2);
nameValuePairs.put("parm3", parm3);
return nameValuePairs;
}
};
addToRequestQueue(stringRequest, "", getApplicationContext());
Volley almacena automáticamente cualquier solicitud y para superar esta situación, es necesario establecer el setShouldCache
atributo a false
.
request.setShouldCache(false);
myQueue.getCache().clear();
myQueue.add(request);
Aquí hay una solicitud completa copiado del tema Github .
RequestQueue queue = Volley.newRequestQueue(context);
queue.getCache().clear();
StringRequest myReq = new StringRequest(Request.Method.POST,
VolleyConnector.url,
createMyReqSuccessListener(),
createMyReqErrorListener()) {
protected Map<String, String> getParams() throws com.android.volley.AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("Cn","1");
params.put("Yr","1396");
params.put("MaxInPage","10");
params.put("Method","Control_Vaziat_View");
params.put("Pg","1");
return params;
};
};
myReq.setShouldCache(false);
queue.add(myReq);
¡Espero que ayude!