Below is a method in which I am trying to retrieve an user object by calling getSelf(). Problem is that the result is always null since the Volley request has not finished a
You can achieve this using the library VolleyPlus https://github.com/DWorkS/VolleyPlus
It has something called VolleyTickle and RequestTickle. Request is the same. It is synchronous Request and only one request at time.
For those coming to this question from search & google.
There is no reason to wait for an async request to finish, as it is asynchronous by design. If you want to achieve synchronous behaviour using Volley, you have to use so-called futures:
String url = "http://www.google.com/humans.txt";
RequestFuture<String> future = RequestFuture.newFuture();
StringRequest request = new StringRequest(Request.Method.GET, url, future, future)
mRequestQueue.add(request);
String result = future.get(); // this line will block
Keep in mind that you have to run blocking code in another thread, so wrap it into AsyncTask
(otherwise future.get()
will block forever).