0

In my application, I made a volley request and it is working fine, but when the response does not reach the user, the loader keeps loading and it doesn't stop. What should I do? How do I stop volley requests after 1 min if the response is nothing?

Daniel
  • 2,355
  • 9
  • 23
  • 30
kasper
  • 1
  • 2
  • 2
    Can you share your code? – D. B. Oct 10 '18 at 16:48
  • 1
    have a look: https://stackoverflow.com/questions/52464832/how-to-cancel-volley-request-if-there-is-no-response-in-10-seconds/52464951 https://stackoverflow.com/a/32793963/6176507 – Md. Zakir Hossain Oct 10 '18 at 17:11
  • @Md.ZakirHossain if those contain the answers to this question then you should flag this as a duplicate question. – Graham Oct 11 '18 at 00:10
  • Possible duplicate of [how to cancel volley request if there is no response in 10 seconds](https://stackoverflow.com/questions/52464832/how-to-cancel-volley-request-if-there-is-no-response-in-10-seconds) – Graham Oct 11 '18 at 00:10

1 Answers1

1

you need to implement the ErrorListener and setRetryPolicy method and dismiss the progress in onErrorResponse method

    JsonObjectRequest myRequest = new JsonObjectRequest(Method.GET,
    url, null,
    new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject response) {
            Log.d(TAG, response.toString());
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            progressdialog.dismiss()
            Log.d(TAG, "V_Error: " + error.getMessage());
             /*if (volleyError.getClass().equals(TimeoutError.class)) {
                // Show timeout error message
             }*/
        }
     });

     myRequest.setRetryPolicy(new DefaultRetryPolicy(
             7000,//Socket time out in milies
             DefaultRetryPolicy.DEFAULT_MAX_RETRIES, 
             DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
Zahoor Saleem
  • 614
  • 7
  • 15