-1
我知道可以取消Volley等待請求,那麼已經啓動的那個呢?如何取消或忽略已經開始的排球請求?
我知道可以取消Volley等待請求,那麼已經啓動的那個呢?如何取消或忽略已經開始的排球請求?
試試這個:
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);