Android Volley

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

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/



Got any Android Question?