Volley library o An open-source library written by Google (Android team) o Volley isn’t an image loading library - it’s an asynchronous networking library o Introduced by Ficus Kirkpatrick at Google I/O 2013 o It’s not yet added to Android API
Advantages o Standalone library o A high level API to make asynchronous RESTful HTTP requests o Schedules all your HTTP requests running them parallel in background threads and manages those threads. o Good asynchronous performance o Provides powerful cancellation request API. o Comes with inbuilt JSON parsing the response. o Handles memory errors well o Retry policy for timeout, certain ERROR codes as Internal Server error.
Let’s use Volley Step 1: Create a RequestQueue Instance Step 2: Create a JSONObjectRequest with response and error listener. Step 3: Add your request into the RequestQueue.
Step 2 To make asynchronous HTTP requests, there are 3 utility classes available: JsonObjectRequest - To send and receive JSON Object from the Server JsonArrayRequest - To receive JSON Array from the Server StringRequest - To retrieve response body as String (ideally if you intend to parse the response by yourself)
Step 2 Create a JSONObjectRequest with response and error listener. JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener() { @Override public void onResponse(JSONObject response) { // TODO Auto-generated method stub } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { // TODO Auto-generated method stub } });
Image loading using Volley Step 1: Get NetworkImageView in XML layout Step 2: Create ImageLoader object Step 3: Load Image using setImageUrl(url, imageLoader)