Android Volley Custom Request-Java Object as Response

This example is for sending a Custom Request in Volley. If you are new to Volley and want to learn how to send a simple GET, POST request in Volley read this

I always have preferred Volley library over Retrofit for sending network requests in an Android Application mostly because of its cache handling  and request prioritization. But many Retrofit users argue that one of the biggest advantage with Retrofit is that it automatically parses the json/xml response not knowing that the same could be done with Volley.  You already know that Volley provides inbuilt support which will gives us response in any of these three formats

  • String
  • JSONObject
  • JSONArray

Now using a custom request with the help of Gson you can directly receive response in the form of POJO- Java Objects

Continue reading

Android Volley example with Error Handling

android_error_handling

In my previous post we learnt how to send GET,POST request using volley in Android. As we had seen every Volley requests has two callbacks -one for success and one for failure. While this might make sense if the request is successful but would lead to confusion if the error callback is called- as the developer doesn’t know why the request actually failed. A request could fail due to multiple reasons

  • No internet connection
  • Very slow internet connection- com android volley timeoutError
  • An expired login session- com volley android volley AuthfailureError
  • Server is down or is unable to process the request- com android volley ServerError
  • Client not able to parse(read) the response

Continue reading

Android Volley Example- HTTP GET,POST with Custom Headers

Nowadays almost every app is required to send a network request. And for a beginner in android development sending a network request should be one the first concepts he should learn.

In Android all time-consuming tasks (like a network request) are to be performed on the background thread. While developing Java Application you must have used  HttpsUrlConnection to send network request. In Android sending requests using HttpsURLConnection that too on a background thread and then sending the response back on the  main thread might make you believe that performing network operations is very complicated in Android. Fortunately Android Volley has made it pretty simple.

android_volley_example

What is Android Volley

Volley is a HTTP library used for performing network requests in Android. It is quite popular among Android developers reason being that it moves all the complicated stuff under the hood and makes sending a network request ridiculously easy. Following are the things volley takes care of on its own

Continue reading