2017-08-18 83 views

回答

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);