我使用的是Volley库。我有一个问题。我在N秒(30秒)后无法停止请求 这是来源
private void searchTrains() {
RequestQueue queue = Volley.newRequestQueue(getActivity());
GlobalParameters.pDialog = new TrainCustomLoader(getActivity());
GlobalParameters.pDialog.show();
GlobalParameters.pDialog.setCancelable(false);
String url = TrainUrls.trains();
UTF8VolleySupport sr = new UTF8VolleySupport(Request.Method.GET, url, new Response.Listener<String>() {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onResponse(final String response) {
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
if (GlobalParameters.pDialog != null)
GlobalParameters.pDialog.dismiss();
NetworkResponse errorRes = error.networkResponse;
String stringData = "";
int statusCode = errorRes.statusCode;
if (errorRes != null && errorRes.data != null) {
try {
stringData = new String(errorRes.data, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
Log.e("Error", stringData);
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("Accept", "application/json");
params.put("Authorization", "Bearer" + " " + token);
return params;
}
};
sr.setRetryPolicy(new DefaultRetryPolicy(
30000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
queue.add(sr);
}
正如我所说,我可以从服务器得到回复,但我不能在30秒后停止请求 我怎么能解决我的问题?