Question

I've seen answer to both of these questions, however, when I tried to put them together, I couldn't make it work. The problem itself is pretty simple: I want to get a string from one site and use it in a post request. That means I can only make the post request after I've finished parsing the GET request. The main ideas I'm using are these ones:

How to return response header field to main method using Google Volley for HTTP GET request in Android / Java?

Can I do a synchronous request with volley?

However the synchronous request is blocked and doesn't go on, and the first one is Async.

I believe this to be a simple thing to do, but still, I haven't be able to do it...

Thanks for any help!

Was it helpful?

Solution

Why not do something like this:

// send first request
requestQueue.add(firstRequest, null, new Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {

            // ** code to parse response **

            // send second request
            requestQueue.add(secondRequest, null, new Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                   // ** code to parse response **
                }
            }, new ErrorListener() {
               @Override
               public void onErrorResponse(VolleyError error) {
                   // ** code to handle errors **
               }
            }));
        }
    }, new ErrorListener() {
       @Override
       public void onErrorResponse(VolleyError error) {          
           // ** code to handle errors **
       }
}));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top