I am working on a chat application where I am using FCM, PHP back-end, and Volley for requests.
Initially, when I log in to my application, chat works fine, and fast, but after sometime volley timeout error start coming up and as I am not using any retry policy, chat message gets lost.
And if I increase socket time out and use retry policy then app gets hung.
Here is my code snippet where I am calling API:
public void doNetworkRequest(int type, String url, final HashMap<String, String> params, Response.Listener requestListener, Response.ErrorListener errorListener) {
StringRequest mRequest = new StringRequest(type, url, requestListener, errorListener) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
return headers;
}
};
// int socketTimeout = 500000;
// RetryPolicy policy = new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
// mRequest.setRetryPolicy(policy);
mQueue.add(mRequest);
}
This issue is coming almost every API sometimes like login, logout, chatting etc.
try this code
request.setRetryPolicy(new DefaultRetryPolicy(20 * 1000, 1, 1.0f));
this is for Retrying failed requests and customizing request Timeout
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With