I am facing a problem where my POST
request parameters are not going to server after 1st time. I know Volley
is using cache mechanism for responses, but in my case my request parameter values can be changed at runtime as i am using pagination in Recyclerview
.
So my questions is how can i send Post request parameter every time and wont loose cache mechanism of volley
.
I have tried using below ones and get my things done (calling getParams()
every-time).. but it loses caches response and i don't want that.
requestQueue.getCache().clear();
stringRequest.setShouldCache(false);
Also have Searched Google and below links but cant find any proper solution. below are the SO links
- Volley not calling getParams() for second time
- Volley not calling getParams()
- Android volley does not calling getParams in POST request
- Volley not calling getParams() for standard POST request
Below is my code:
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e("RES", response);
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setDateFormat("M/d/yy hh:mm a"); //Format of our JSON dates
Gson gson = gsonBuilder.create();
NewsFeedPOJO resultObj = (NewsFeedPOJO) gson.fromJson(response, (Class) NewsFeedPOJO.class);
inCurrPage = Integer.parseInt(resultObj.getPagination().getCurrent_page());
inTotalPage = Integer.parseInt(resultObj.getPagination().getTotal_pages());
inCurrPage++;
arrayList.addAll(resultObj.getNewsFeedList());
if (isFtym) {
isFtym = false;
layoutManager = new LinearLayoutManager(MainActivity.this);
rcNewsFeed.setLayoutManager(layoutManager);
adapter = new NewsFeedAdapter(MainActivity.this, arrayList);
rcNewsFeed.setAdapter(adapter);
} else {
adapter.notifyItemInserted(arrayList.size());
adapter.notifyDataSetChanged();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> map = new HashMap<>();
map.put("user_id", "188");
if (inCurrPage == 0)
map.put("page", "1");
else {
map.put("page", "" + inCurrPage);
}
Log.e("RES", inCurrPage + " PARA");
return map;
}
};
//RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);
//requestQueue.add(stringRequest);
//requestQueue.getCache().clear();
//AppController.getInstance().addToRequestQueue(stringRequest);
// stringRequest.setShouldCache(false);
VolleySingleton.getInstance(this).addToRequestQueue(stringRequest);
using below Volley Dependency.
compile 'com.android.volley:volley:1.1.0'
If need more information please do let me know. Thanks in advance. Your efforts will be appreciated.