Introducing Volley – A Networking Library

Have you ever heard of “Volley” word yet in android development? This tutorial is all about a library which google has delivered in Google I/O early in 2013. The library was given a name “Volley”

You probably have an idea what it is used for and what it is, if not you will have it by the end of this tutorial.

So, What is Volley library and for what it is used exactly?

Volley is a library that makes networking in Android faster and easier. It works in such a manner which saves our time from writing repetitive network code for processing and caching of network requests.

I use AsyncTask for network call code usually. We have to take care of displaying ProgressBar/ProgressDialog inside onPreExecute() and onPostExecute(). But now we can say that Volley can be a powerful replacement of AsyncTask.

Why use Volley:

1.) Volley automatically schedule all network requests.
2.) Volley provides transparent disk and memory caching.
3.) Volley provides powerful cancellation request API.
4.) Volley provides powerful customization abilities.
5.) Volley provides Debugging and tracing tools

To get started Clone the Volley project from GIT and import it into your project. You can clone it either by Git client or by Eclipse and ADT Bundle. Eclipse is having an option to clone repository and import project directly.

Let’s have a look on the classes of volley now. It includes 2 main classes:

Request queue : This class is used for dispatching requests to the network.

Request : It includes all the necessary details for making web API call. For example: which method to Use (GET or POST).

Follow the steps below to create an example using Volley:

Step 1: Make sure to import Volley projects into Eclipse. After importing, you need to make it a Library project by Right click => Properties => Android.


Step 2: Create a new project with the name VolleySampleProject, Right click on it and Include Volley Library in this project.


Step 3: Make sure you have includes INTERNET permission in your manifest file.


<uses-permission android:name="android.permission.INTERNET"/>



Step 4: Write following into your :


package com.example.volleysampleproject;

import org.json.JSONObject;

import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;


public class MainActivity extends Activity {

private TextView txtToDisplay;

protected void onCreate(Bundle savedInstanceState) {

txtToDisplay = (TextView) findViewById(;

RequestQueue queue = Volley.newRequestQueue(this);
String url = "";

JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {

public void onResponse(JSONObject response) {
// TODO Auto-generated method stub
txtToDisplay.setText("Response => "+response.toString());
}, new Response.ErrorListener() {

public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub




public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(, menu);
return true;



Step5: Setup your layout xml and run for the output.

Check out my previous post on Android TV – Introduction.

Leave a Comment: