How to make Synchronous HTTP Request in Android Using Volley library

Updated 31 January 2019

Save

Add dependency for Volley library in your build.gradle.

Volley is a network library which makes fast and easier to make HTTP Request for android application. Using Volley library we don’t need to create AsyncTask to make multiple API calls in volley there is RequestQueue where we can enqueue each request. Here in this example, We used Google place autocomplete API. We are going to make synchronous HTTP Request using volley. To make synchronous HTTP request make a RequestFuture object. And make JsonObjectRequest pass this parameter RequestMethod, URL, pass object of type Json and pass RequestFuture instance.

Add your request in RequestQueue. Now, whenever the user makes an HTTP request each request added to RequestQueue.To get response object from the requestFuture we call get() method. And we also set a timeout of let’s say 10 seconds so we don’t block the UI thread indefinitely in case our request times out.

Hope this helps you to understand how we can use volley used to make the synchronous HTTP request.

 

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


3 comments

  • L
    • manish choudhary (Moderator)
  • sf
  • Start a Project


      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home