use of com.android.volley.DefaultRetryPolicy in project ShoppingCart by joefei.
the class VollyHelperNew method sendRequestPostOfJSON.
public RequestQueue sendRequestPostOfJSON(String url, JSONObject object, final Handler handler, final int what) {
JsonObjectRequest json = new JsonObjectRequest(Method.POST, url, object, new Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
checkResponse(response, handler, what);
}
}, new ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
sendError(handler, error);
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
return TokenUtils.getHeaders(context);
}
};
json.setRetryPolicy(new DefaultRetryPolicy() {
@Override
public int getCurrentRetryCount() {
return 2;
}
});
mQueue.add(json);
return mQueue;
}
use of com.android.volley.DefaultRetryPolicy in project ShoppingCart by joefei.
the class VollyHelperNew method sendRequest.
/**
* @param url 请求地址
* @param map 请求参数列表
* @param handler 请求界面的Handler
* @param what 请求界面的上下文
* @param method 请求方式 POST | PUT | GET
* @author WuGefei
*/
public RequestQueue sendRequest(String url, HashMap<String, String> map, final Handler handler, final int what, int method) {
JSONObject jo = null;
if (method != Method.GET || map != null) {
jo = new JSONObject(map);
}
JsonObjectRequest json = new JsonObjectRequest(method, url, jo, new Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
checkResponse(response, handler, what);
}
}, new ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
sendError(handler, error);
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
return TokenUtils.getHeaders(context);
}
};
/* 解决重复请求问题 */
json.setRetryPolicy(new DefaultRetryPolicy(60000, 0, 1f) {
@Override
public int getCurrentRetryCount() {
/*
* Volley默认尝试两次,MAX=1,count=0;count<=MAX;count++;count=2时,
* 表示当前已经重复请求两次,就不会再第三次重复请求,从而屏蔽掉Volley的自动重复请求功能;
*/
return 2;
}
});
mQueue.add(json);
return mQueue;
}
use of com.android.volley.DefaultRetryPolicy in project EasyVolley by asifmujteba.
the class ASFRequest method start.
public void start() {
if (mRequestQueueWeakReference.get() != null && getRequest() != null) {
if (shouldUseCache() && isCachableHTTPMethod() && getCache() != null) {
ASFCache.ASFEntry entry = getCache().get(getCacheKey());
if (entry != null) {
try {
getResponseListener().onResponse((T) entry.getData());
return;
} catch (ClassCastException e) {
}
}
}
if (!shouldUseCache()) {
getRequest().setShouldCache(false);
}
getRequest().setRetryPolicy(new DefaultRetryPolicy(mNetworkTimeoutTime, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
mRequestQueueWeakReference.get().add(getRequest());
mRequestQueueWeakReference.get().start();
EasyVolley.addedRequest(this);
}
}
Aggregations