RequestQueue queue = Volley.newRequestQueue(this); String url = "http://www.baidu.com/"; StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener() { @Override public void onResponse(Object response) { Log.e("onResponse", response.toString()); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e("onErrorResponse", "error"); } }); //設置TAG,能夠在界面關閉的時候取消該TAG的全部請求 stringRequest.setTag("TAG"); queue.add(stringRequest);只要將Request(請求)加入到隊列中volley就會本身去請求並返回。
@Override protected void onStop() { super.onStop(); if (queue != null) { <pre name="code" class="java"> //取消該Tag下全部請求的返回。queue.cancelAll("TAG");}}
版權聲明:本文爲博主原創文章,未經博主容許不得轉載。java