I need to get the response 8 times nearly(dynamic) based on the array list size.So I had used for loop.inside the for loop, I am using volley get response.
While hitting the api everytime,I need to get the onResponse.
Below I have posted the logcat and relevant code:
Logcat: (Edited)
E/getAvaArrStr:
E/urlAva:
E/getAvaArrStr:
E/urlAva:
E/getAvaArrStr:
E/urlAva:
E/getAvaArrStr:
E/urlAva:
E/getAvaArrStr:
E/urlAva:
/* Response */
E/ResponseAvatar:
E/url:
E/CheckArrBit:
E/ResponseAvatar:
E/url:
E/CheckArrBit:
E/ResponseAvatar:
E/url:
E/CheckArrBit:
E/ResponseAvatar:
E/url:
E/CheckArrBit:
CardsFragment.java: (Edited)
RequestQueue queue = Volley.newRequestQueue(getActivity());
for (int i = 0; i < alAvaArr.size(); i++) {
getAvaArrStr = alAvaArr.get(i);
Log.e("getAvaArrStr", "" + getAvaArrStr);
urlAva = BurblrUtils.BR_AVATAR_IMAGE + getAvaArrStr + "&android=1";
Log.e("urlAva", urlAva);
requestAva = new StringRequest(Request.Method.GET, urlAva, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
if (response != null && !response.startsWith("<HTML>")) {
Log.e("ResponseAvatar", response);
dialog.dismiss();
try {
Toast.makeText(getActivity(), "Running ", Toast.LENGTH_SHORT).show();
String url = response.replace("\\", "");
url = url.replace("\"", "");
Log.e("url", url);
arrBitMap.add(url);
Log.e("CheckArrBit", "" + arrBitMap);
// Glide.with(getActivity()).load(url).placeholder(R.drawable.ic_launcher).error(R.drawable.ic_launcher).into(img);
getSwipeImage();
myAppAdapter.notifyDataSetChanged();
} catch (Exception e) {
e.printStackTrace();
dialog.dismiss();
}
} else {
dialog.dismiss();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (error != null) {
Log.e("error", error.toString());
dialog.dismiss();
}
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("file", getAvaArrStr);
Log.e("paramsImg", "" + params);
Log.e("RunningParams", "Testing");
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("Content-Type", "application/x-www-form-urlencoded");
return params;
}
};
queue.add(requestAva);
queue.getCache().remove(urlAva);
}
Expected Log Response Sequence:
E/getAvaArrStr: -> E/urlAva: -> E/ResponseAvatar: -> E/url: -> E/CheckArrBit:
I need to get the response everytime on running the loop.That means nearly 8 times, based on the arrayList size, I have to get the response message,is it possible in volley? any suggestion to overcome this issue.
You are creating the RequestQueue
inside the for loop...
So there is no Call Queue...Move it out of the for loop
RequestQueue queue = Volley.newRequestQueue(getActivity());
for(..){
...
queue.add(requestAva);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With