Handle Multiple request in Android volley

Viewed 11325

I am trying to hit multiple request using Volley and i am getting response for all the request. my problem is how to identify the response is belong to which API.

mQueue = CustomVolleyRequest.getInstance(this.getApplicationContext())
            .getRequestQueue();

    final CustomJSONObjectrequest jsonRequest = new CustomJSONObjectrequest(Request.Method
            .GET, url,
            new JSONObject(), this, this); // 
    jsonRequest.setTag(REQUEST_TAG);

    final CustomJSONObjectrequest jsonRequest2 = new CustomJSONObjectrequest(Request.Method
            .GET, url2,
            new JSONObject(), this, this);
    jsonRequest2.setTag(REQUEST_TAG);
    mButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mQueue.add(jsonRequest);
            mQueue.add(jsonRequest2); // Both the request will have different API request
        }
    });
}
@Override
public void onErrorResponse(VolleyError error) {
    mTextView.setText(error.getMessage());
}

@Override
public void onResponse(Object response) {

    // How to identify, which response is belong to which api request
    mTextView.setText("Response is: " + response);

}
2 Answers
Related