In my application i use volley very much times, and every time i need to create class because different params.
Is there a way to reuse volley multiple times with different params ?
private void sendReservation(String url) {
StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
//Creating parameters
Map<String, String> params = new Hashtable<String, String>();
//Adding parameters
User user = prefManager.getUser();
params.put("id", Id);
return postParams.checkParams(params);
}
};
RequestQueue requestQueue = Volley.newRequestQueue(getActivity());
int x = 0;// retry count
stringRequest.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 48,
x, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
requestQueue.add(stringRequest);
}
Above class i use it with similar request that have the same params.
What i need is to reuse the same method sendReservation()
with more than 1 params or what ever params i pass.
Assume i have one thread post 2 params like :
params.put("id", Id);
params.put("name", name);
and another post three params like :
params.put("id", Id);
params.put("name", name);
params.put("type", type);
How to handle that ?
feel free to ask any question.