I have an Android application with multiple REST Api's. The API's are managed using the Volley library. The response is getting and it's woking fine. But when I make asynchronous requests, I can't identify the response of each request.
My request method is this:
private void httpCall(String URL, String json, String session key, int type) {
try {
SSLContext sslcontext = SSLContext.getInstance("TLSv1");
sslcontext.init(null,
null,
null);
SSLSocketFactory NoSSLv3Factory = new NoSSLv3SocketFactory(sslcontext.getSocketFactory());
HttpsURLConnection.setDefaultSSLSocketFactory(NoSSLv3Factory);
Log.i(REQUEST_TAG, "httpCall=url" + url + "::type" + type);
Log.i(REQUEST_TAG, "httpCall=json" + json);
} catch (Exception e) {
e.printStackTrace();
}
if (mContext != null)
mQueue = CustomVolleyRequestQueue.getInstance(mContext).getRequestQueue();
else
mQueue = CustomVolleyRequestQueue.getInstance(mActivity).getRequestQueue();
JSONObject mJSONObject;
final CustomJSONObjectRequest jsonRequest;
try {
if ((json != null) && (json.trim().length() > 0)) {
mJSONObject = new JSONObject(json);
} else {
mJSONObject = new JSONObject();
}
jsonRequest = new CustomJSONObjectRequest(sessionkey, type, url, mJSONObject, this, this);
// Wait 20 seconds and don't retry more than once
jsonRequest.setRetryPolicy(new DefaultRetryPolicy(
(int) TimeUnit.SECONDS.toMillis(20),
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
jsonRequest.setTag(REQUEST_TAG);
mQueue.add(jsonRequest);
} catch (JSONException e) {
e.printStackTrace();
}
}
Is there any option to set a tag to the request and get the same from the response?. So that I can identify the current request and response. I don't know this is a duplicate question, but I didn't get a proper explanation for this.
My Response method is:
@Override
public void onResponse(Object response) {
if (response != null) {
// I want to trigger the request tag from here
mCallBack.onSuccessData(response);
}
}
The request and response method are in same class and the class implemented Response.Listener, Response.ErrorListener.