0

Hi everybody my question is how do i combine two response from volley? im getting back json and can compare the to json feedback
i have been searching for a while now and this is what i found :

        JsonObjectRequest request1 = new JsonObjectRequest(Request.Method.POST, url, requestbody,  new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            JSONObject response1 = response;
            JsonObjectRequest request2 = new JsonObjectRequest(Request.Method.POST, urlStatus, requestbody2, new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    // do something with response1 & response here...
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.i("onErrorResponse", error.toString());
                }
            });
            mQueue.add(request2);
        }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.i("onErrorResponse", error.toString());
            }
        });
    mQueue.add(request1);

but dont understand the requestbody can somebody help me out this one

  • It's unclear what specific problem you're trying to solve here. To enable others to help you, describe the exact behavior you expected, as well as how that behavior differs from what is happening with your current implementation. Include your code and the exact text of any error messages (including, for any exceptions, the full [stack trace](/a/23353174) and which line of code is producing it). Please see [How do I ask a good question?](/help/how-to-ask) and [How to create a Minimal, Reproducible Example](/help/minimal-reproducible-example). – Ryan M May 12 '20 at 20:52
  • I would advise against nesting your requests like this, unless perhaps the order of the requests is important? Not only does it look unclear but it is also slow as you cannot run the requests concurrently. I would suggest a implementing a simple test (a boolean flag) for when each response is received and each to check whether the other has completed to determine if it is second, and therefore should process the combined response. – codebod May 13 '20 at 15:24
  • @codebod how would you do this, to be able to put it together quickly and to do some calculations like ' if(response1.equals("test") || response.equals("test")) { //do something } ' – klappernoot May 13 '20 at 16:45

0 Answers0