Android Volley – Second Part of Two

The whole reason why the Android Volley library is being used, will be shown in the following tutorial. It will be used to parse the JSON data being retrieved from the database. JSON is very light weight, structured, easy to parse and much human readable. JSON is best alternative to XML when an Android app needs to interchange data with the PHP server.

Written by Ficus Kirkpatrick and his team, Volley is a library recently released by Google at I/O 2013. The Google Play Store and a number of apps by Google use this library to perform network requests and remote image loading. The developers at Google claim that network requests performed through Volley are up to 10 times faster than other libraries according to their tests. Volley is a Google library for Android that makes networking and remote image loading easier and faster.

In the below code, the two methods makeJsonObjectRequest() and makeJsonArrayRequest() are instantiantaed but are kept empty for the time being:

private String jsonResponse;
    private void makeJsonObjectRequest() {
    }

    private void makeJsonArrayRequest() {
    }

The above methods need to wrap the JSONParser class.

Normally JSON responses can be of two different types. It can be either a JSON object or JSON array. If the json starts with {, it is considered to be JSON Object, while when starting with [, then it is a JSON Array. Volley provides JsonObjectRequest class to make json object request. Here we are fetching the JSON data by making a call to a url and parsing it. Finally the parsed response is appended to a string and displayed on the screen.

The JSON parsing code remains the same as implemented beforehand.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.