Volley

Download android eBook

Introduction

Volley is an Android HTTP library that was introduced by Google to make networking calls much simpler. By default all the Volley network calls are made asynchronously, handling everything in a background thread and returning the results in the foreground with use of callbacks. As fetching data over a network is one of the most common tasks that is performed in any app, the Volley library was made to ease Android app development.

Syntax

  • RequestQueue queue = Volley.newRequestQueue(context); // setup the queue
  • Request request = new SomeKindOfRequestClass(Request.Method, String url, Response.Listener, Response.ErrorListener); // setup some kind of request, the exact type and arguments change for each request type
  • queue.add(request); // add the request to the queue; the appropriate response listener will be called once the request is finished (or terminated for whatever reason)

Remarks

Installation

You can build Volley from the official Google source code. For a while, that was the only option. Or using one of the third-party pre-built versions. However, Google finally released an official maven package on jcenter.

In your application-level build.gradle file, add this to your dependencies list:

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

Ensure the INTERNET permission is set in your app's manifest:

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

Official Documentation

Google has not provided very extensive documentation on this library, and they haven't touched it in years. But what is available can be found at:

https://developer.android.com/training/volley/index.html

There is unofficial documentation hosted on GitHub, although there should be a better location to host this in the future:

https://pablobaxter.github.io/volley-docs/

Related Examples

Stats

461 Contributors: 13
Tuesday, June 27, 2017
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook