First create a Listener that give response from your volly class
/** Callback interface for delivering parsed responses. */
public interface Listener {
/** Called when a response is received. */
public void onResponse(Object tag, JSONObject response);
public void onErrorResponse(Object tag, VolleyError error);
}
And now create method as below where you pass listener and tag and call volly request. in response you able get tag and response at same time.
public void callApi(String url, final Listener listener, final Object tag){
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
listener.onResponse(tag,response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
listener.onErrorResponse(tag,error);
}
});
// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsonObjReq);
}
Its just sample code, You can modify on your requirement. If you need any help comment.
Request
class and make your own. – Shabuoth