我知道可以取消Volley挂号请求,那已经开始的那个怎么样?
答案 0 :(得分:1)
试试这个:
RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
String url = "Your url";
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(MainActivity.this, "Response is: "+ response.substring(0,5), Toast.LENGTH_SHORT).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, "That didn't work!", Toast.LENGTH_SHORT).show();
}
});
stringRequest.setRetryPolicy(new DefaultRetryPolicy(0, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
queue.add(stringRequest);
queue.cancelAll(stringRequest);