Android Volley Example

Package

com.android.volley

Gradle Dependency

dependencies {
    compile 'com.android.volley:volley:1.0.0'
}

Send a Request

final TextView mTextView = (TextView) findViewById(R.id.text);
...

RequestQueue queue = Volley.newRequestQueue(this); 
String url ="http://www.google.com";

StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
            new Response.Listener() {
    @Override
    public void onResponse(String response) {
        mTextView.setText("Response is: "+ response);
    }
}, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        mTextView.setText("That didn't work!");
    }
});

queue.add(stringRequest); // Add the request to the RequestQueue.

Cancel a Request

public static final String TAG = "MyTag";
StringRequest stringRequest;
RequestQueue mRequestQueue;  

stringRequest.setTag(TAG); // Set the tag on the request.

mRequestQueue.add(stringRequest);

@Override
protected void onStop () {
    super.onStop();
    if (mRequestQueue != null) {
        mRequestQueue.cancelAll(TAG);
    }
}