我正在开发使用Volley库进行网络通话的Android应用。 如果屏幕超时,则http正在进行调用,API调用将被拒绝。
如果有人遇到同样的问题,请提供一些与此相关的信息。
这是我的代码:
CustomStringRequest customStringRequest = new CustomStringRequest(
Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// TODO Auto-generated method stub
try {
JSONObject jsonObject = new JSONObject(response);
if (jsonObject.getBoolean(JSONHelper.TAG_SUCCESS)) {
iNetworkOperationHandler.onResponseSucceed(
jsonObject, requestId, extraInfo);
} else if (!jsonObject
.getBoolean(JSONHelper.TAG_SUCCESS)) {
iNetworkOperationHandler.onResponseFailed(
response, requestId, extraInfo);
} else {
iNetworkOperationHandler.onResponseError(
response, requestId, extraInfo);
}
} catch (JSONException e) {
e.printStackTrace();
iNetworkOperationHandler.onJSONException(e,
requestId, extraInfo);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
iNetworkOperationHandler.onErrorReceived(error,
requestId, extraInfo);
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
if (null != headers) {
return headers;
} else {
return UrlClass.getHeader();
}
}
};
customStringRequest.setRetryPolicy(new DefaultRetryPolicy(
ApplicationBaseLimits.TIMEOUT_NORMAL_MILLISECONDS, 0, 1f));
customStringRequest.setShouldCache(false);
appCntrlr.addToRequestQueue(customStringRequest, TAG);
提前致谢。