I have a problem with Volley GET request on slow network. Everytime I see BasicNetwork.logSlowRequests in my LogCat, my GET request is executed twice or more resulting multiple (2 or more) postings for 1 request. I already set the retry policy but It doesn't help.
This is my LogCat
03-16 01:31:35.674: D/Volley(5984): [19807] BasicNetwork.logSlowRequests: HTTP response for request=<[ ] http://[myserver]/api/places 0xfa7d0c33 NORMAL 1> [lifetime=3824], [size=313], [rc=200], [retryCount=0] 03-16 01:31:35.704: D/Volley(5984): [1] Request.finish: 3853 ms: [ ] http://[myserver]/api/places 0xfa7d0c33 NORMAL 1
my code:-
StringRequest strReq = new StringRequest(Request.Method.GET,
url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
pd.dismiss();
getColorDetails.getColorresponse(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
pd.dismiss();
if (error instanceof TimeoutError || error instanceof NoConnectionError) {
showSignOutAlertDialog(context, "TimeoutError");
} else if (error instanceof AuthFailureError) {
showSignOutAlertDialog(context, "AuthFailureError");
} else if (error instanceof ServerError) {
showSignOutAlertDialog(context, "ServerError");
} else if (error instanceof NetworkError) {
showSignOutAlertDialog(context, "NetworkError");
} else if (error instanceof ParseError) {
showSignOutAlertDialog(context, "ParseError");
}
}
}) {
/**
* Passing some request headers
* */
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
//headers.put("Content-Type", "application/json; charset=utf-8");
return headers;
}
@Override
public String getBodyContentType() {
return "application/json";
}
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
int mStatusCode = response.statusCode;
System.out.println("Status code is===>"+mStatusCode);
return super.parseNetworkResponse(response);
}
};
strReq.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 2, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
AppController.getInstance().addToRequestQueue(strReq);
}
AppController.getInstance().addToRequestQueue(strReq);
toMyVolley.getRequestQueue().add(strReq);
. It worked normally. – Parcenary