本文整理汇总了Java中com.android.volley.Request.setRetryPolicy方法的典型用法代码示例。如果您正苦于以下问题:Java Request.setRetryPolicy方法的具体用法?Java Request.setRetryPolicy怎么用?Java Request.setRetryPolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.android.volley.Request
的用法示例。
在下文中一共展示了Request.setRetryPolicy方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: placeJsonArrayRequest
import com.android.volley.Request; //导入方法依赖的package包/类
/**
* @param apiTag tag to uniquely distinguish Volley requests. Null is allowed
* @param url URL to fetch the string at
* @param httpMethod the request method to use (GET or POST)
* @param params A {@link JSONArray} to post with the request. Null is allowed and
* indicates no parameters will be posted along with request.
* @param headers optional Http headers
* @param serverCallback Listener to receive the String response
*/
public void placeJsonArrayRequest(@Nullable final String apiTag, String url, int httpMethod, @Nullable JSONArray params, final @Nullable HashMap<String, String> headers, final ServerCallback serverCallback) {
Request request = new JsonArrayRequest(httpMethod, url, params, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
serverCallback.onAPIResponse(apiTag, response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
serverCallback.onErrorResponse(apiTag, error);
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
return headers != null ? headers : super.getHeaders();
}
};
request.setRetryPolicy(retryPolicy);
addToRequestQueue(request);
}
示例2: postRequest
import com.android.volley.Request; //导入方法依赖的package包/类
public void postRequest(Request<?> request){
request.setRetryPolicy(new DefaultRetryPolicy(10000,
DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
mQueue.add(request);
}
示例3: placeJsonObjectRequest
import com.android.volley.Request; //导入方法依赖的package包/类
/**
* @param apiTag tag to uniquely distinguish Volley requests. Null is allowed
* @param url URL to fetch the string at
* @param httpMethod the request method to use (GET or POST)
* @param params A {@link JSONObject} to post with the request. Null is allowed and
* indicates no parameters will be posted along with request.
* @param headers optional Http headers
* @param serverCallback Listener to receive the String response
*/
public void placeJsonObjectRequest(@Nullable final String apiTag, String url, int httpMethod, @Nullable JSONObject params, final @Nullable HashMap<String, String> headers, final ServerCallback serverCallback) {
Request request = new JsonObjectRequest(httpMethod, url, params, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
serverCallback.onAPIResponse(apiTag, response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
serverCallback.onErrorResponse(apiTag, error);
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
return headers != null ? headers : super.getHeaders();
}
};
request.setRetryPolicy(retryPolicy);
addToRequestQueue(request);
}
示例4: addToRequestQueue
import com.android.volley.Request; //导入方法依赖的package包/类
public <T> void addToRequestQueue(Request<T> req, Context context) {
req.setTag(TAG);
req.setRetryPolicy(new DefaultRetryPolicy(
MY_SOCKET_TIMEOUT_MS,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
getRequestQueue(context).add(req);
}
示例5: addRequest
import com.android.volley.Request; //导入方法依赖的package包/类
public static void addRequest(Request<?> request, Object tag) {
Helper.showLog("Volley/URL", request.getCacheKey());
if (tag != null) {
request.setTag(tag);
}
request.setRetryPolicy(new DefaultRetryPolicy(15000, 0, 1.0f));
mRequestQueue.add(request);
if (request != null && (request instanceof BaseJsonRequest)) {
cacheIp((BaseJsonRequest) request);
}
}
示例6: placeStringRequest
import com.android.volley.Request; //导入方法依赖的package包/类
/**
* @param apiTag tag to uniquely distinguish Volley requests. Null is allowed
* @param url URL to fetch the string at
* @param httpMethod the request method to use (GET or POST)
* @param params A HashMap<String,String> to post with the request. Null is allowed and
* indicates no parameters will be posted along with request.
* @param headers optional Http headers
* @param serverCallback Listener to receive the String response
*/
public void placeStringRequest(@Nullable final String apiTag, String url, int httpMethod, @Nullable final HashMap<String, String> params, final HashMap<String, String> headers, final ServerCallback serverCallback) {
Request request = new StringRequest(httpMethod, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
serverCallback.onAPIResponse(apiTag, response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
serverCallback.onErrorResponse(apiTag, error);
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
return params != null ? params : super.getParams();
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
return headers != null ? headers : super.getHeaders();
}
};
request.setRetryPolicy(retryPolicy);
addToRequestQueue(request);
}