Hena Shiekh
Hena Shiekh

Reputation: 963

Volley: TimeOutError

i want to fetch some data from a URL and the server is very slow... So whenever i use volley to get the data, I get TimeOurError, Is there anyway i can handle for how long volley should try to get the data as the server is slow...It takes little time and i also want to run this request constantly to check data, I plan to use Timer for it...Is it okay to use Timer for continuously checking data?

Here is my volley request for now...It works for other URL's

public void checkData() {
    StringRequest stringRequest = new StringRequest(Request.Method.POST, URL,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Log.i("Response",response);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.i("Response",error.toString());
                }
            }){
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String,String> map = new HashMap<String,String>();
            map.put("deviceID","none");
            return map;
        }
    };

    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringRequest);

}

and i need to call this functions continuously( inside app)

UPDATE

I used

tringRequest.setRetryPolicy(new DefaultRetryPolicy(
            30000,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

and it worked, Now I want to make this request continuously in my app...What is the best approach for that?

Upvotes: 3

Views: 4728

Answers (4)

Yash Hirapara
Yash Hirapara

Reputation: 1

this code will help to increase the time for volley request try it.And solve Volley: TimeOutError

stringRequest.setRetryPolicy(new DefaultRetryPolicy(
    30000,DefaultRetryPolicy.DEFAULT_MAX_RETRIES,DefaultRetryPolicy.DEFAULT_BACKOFF_MULT
));

Upvotes: 0

Vigneswaran A
Vigneswaran A

Reputation: 590

add these 4 lines to increase the android volley time to 60 seconds

StringRequest myRequest   

or

JsonObjectRequest myRequest

.

RetryPolicy policy = new DefaultRetryPolicy(60000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
myRequest.setRetryPolicy(policy);

RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(myRequest);

Upvotes: 0

islamdidarmd
islamdidarmd

Reputation: 725

You can setRetryPolicy for controlling volly request timeout time.

stringRequest.setRetryPolicy(new DefaultRetryPolicy(
        YOUR_TIMEOUT_MS, 
        DefaultRetryPolicy.DEFAULT_MAX_RETRIES, 
        DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

Have a look at this Qus.

Upvotes: 2

Mohit Kalia
Mohit Kalia

Reputation: 351

StringRequest request = new StringRequest(Request.Method.GET, requestURL, stringListener, errorListener);
        request.setRetryPolicy(new DefaultRetryPolicy(
                30000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

        addToRequestQueue(request);

// this code will help to increase the time for volley request try it.

Upvotes: 0

Related Questions