Change Volley timeout duration
See Request.setRetryPolicy()
and the constructor for DefaultRetryPolicy
, e.g.
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) {
Log.d(TAG, "Error: " + error.getMessage());
}
});
myRequest.setRetryPolicy(new DefaultRetryPolicy(
MY_SOCKET_TIMEOUT_MS,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
Volley RequestQueue Timeout
You should set the request's RetryPolicy:
myRequest.setRetryPolicy(new DefaultRetryPolicy(
MY_SOCKET_TIMEOUT_MS,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
This would change your code to:
RequestQueue mRequestQueue = Volley.newRequestQueue(getApplicationContext());
JsonObjectRequest request = new JsonObjectRequest(Method.GET, cityListUrl, null, new
Listener<JSONObject>() {
public void onResponse(JSONObject jsonResults) {
//Any Call
}
}, new ErrorListener(){
public void onErrorResponse(VolleyError arg0) {
//Any Error log
}
}
);
int socketTimeout = 30000;//30 seconds - change to what you want
RetryPolicy policy = new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
request.setRetryPolicy(policy);
mRequestQueue.add(request);
If you are only just getting started with Volley, you might want to instead consider droidQuery, which is a little easier to configure:
int socketTimeout = 30000;
$.ajax(new AjaxOptions().url(cityListUrl)
.timeout(socketTimeout)
.success(new Function() {
public void invoke($ d, Object... args) {
JSONObject jsonResults = (JSONObject) args[0];
//Any call
}
})
.error(new Function() {
public void invoke($ d, Object... args) {
AjaxError error = (AjaxError) args[0];
Log.e("Ajax", error.toString());
}
}));
Related Topics
Taking Picture from Camera Without Preview
Check If Application Is on Its First Run
Eclipse Error: R Cannot Be Resolved to a Variable
Fcm (Firebase Cloud Messaging) Send to Multiple Devices
Using Both Front and Back Cameras Simultaneously Android
Singleton Object Becomes Null After App Is Resumed
Android.Util.Androidruntimeexception: You Cannot Combine Swipe Dismissal and the Action Bar
Android: Create Spinner Programmatically from Array
Launch Facebook App from Other App
Android 4.1: How to Check Notifications Are Disabled for the Application
How to Make Bitmap Compress Without Change the Bitmap Size
Is There a Broadcast Action for Volume Changes
How to Hide Navigation Bar Permanently in Android Activity
Android Get Free Size of Internal/External Memory
How to Add a Jar in External Libraries in Android Studio
How to Use Support Fileprovider For Sharing Content to Other Apps