0

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!

Community
  • 1
  • 1
Guiga
  • 37
  • 1
  • 13

1 Answers1

-1

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 **
       }
}));
Itai Hanski
  • 8,540
  • 5
  • 45
  • 65
  • Hey Itai Hanski. I though about doing that, but I didn't know if this is considered good practice. I said that because if I want to do many requests the code would became really strange and confusing. Also, I think I'll need this string later on. Anyway, I think I'll start with this and clean it up afterwards if there's better way. Thanks! – Guiga Mar 12 '14 at 17:05
  • Good luck! If my answer works for you, the good practice here is to accept it (that V next to it). – Itai Hanski Mar 16 '14 at 08:22