Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there Any way To hold Volley request until the response Completed

As past when use AsyncTask we have two method doInBackground() to do all work and onPostExecute() to make change when all data back completed, so I can stop all code until the right data come back, then do what I need with this data.

But when I try to move to Volley library, when call request I just have the onResponse() method, but there is problem that I need to do some code depend on back data but there is no way to hold code at this point.

So is there Any way To hold Volley request until the response Completed ?

*I know we can override the onResponse() to do what we need when the full data come back,but this well be a lot of Nested coding and method.

Thanks for all who can help.

like image 508
devqmr Avatar asked Mar 12 '14 17:03

devqmr


People also ask

How do I make my volley request synchronous?

A volley class used for blocking requests. To access the get() method and make an Android Volley synchronous request, you need to use the RequestFuture class instead of standard StringRequest or JsonObjectRequest class. This RequestFuture class also implements both Response. Listener and Response.

What is RequestFuture in volley?

A Future that represents a Volley request. Used by providing as your response and error listeners.

What is volley dependency?

Volley is an HTTP library that makes networking for Android apps easier and most importantly, faster. Volley is available on GitHub. Volley offers the following benefits: Automatic scheduling of network requests. Multiple concurrent network connections.


1 Answers

If you are looking to synchronously perform a request you could use a RequestFuture to wait until the response has been returned. This should not be done on the main thread, as it will cause your UI to lock up.

This has been answered as well here: https://stackoverflow.com/a/18541806

like image 126
Bill Avatar answered Nov 04 '22 14:11

Bill