I have a problem when try to execute requests one after another without user participation. When run app i can see this log
Posting params: {[email protected], tag=getConnectors}
verifyOperation onResponse --> 1 operation
verifyOperation onResponse --> {"result":"85","msg":"ok, user register, your password is your number phone!"}
response 1 operation is ok call -->getConnectors
Posting params: {[email protected], tag=geinfodates}
verifyOperation onResponse --> 2 operation
verifyOperation onResponse -->{"result":"85","msg":"ok, user register, your password is your number phone!"}
But when debug app , the result for the 2 operation is correct:
Posting params: {[email protected], tag=geinfodates}
verifyOperation onResponse --> 2
verifyOperation onResponse -->{"token":"xxxxxxxx"}
I have a singlenton class, where I have my StringRequest
with different types of listeners
void verifyOperation(final HashMap paramOperation, final int opcion,final String url) {
pref = new PrefManager(context);
String urlFinale=url;
StringRequest strReq = new StringRequest(Request.Method.POST,
urlFinale, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
switch (opcion) {
case 1:
if (operation.result >= 0)
break;
case :2 .....
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Error: " + error.getMessage());
Toast.makeText(context,
error.getMessage(), Toast.LENGTH_SHORT).show();
}
}) {
@Override
protected Map<String, String> getParams() {
HashMap<String, String> profile = new HashMap<>();
Set set = paramOperation.entrySet();
Iterator iterator = set.iterator();
//String number=pref.getMobileNumber();
String mail = pref.getMail();
switch (opcion) {
case 1:
break;
case 2:
profile = pref.getUserDetails();
break;
}
and finally add my stringrequest to my singlenton class to control volley request
// Adding request to request queue
MyApplication.getInstance().addToRequestQueue(strReq);
public <T> void addToRequestQueue(Request<T> req) {
req.setTag(TAG);
req.setRetryPolicy(new DefaultRetryPolicy(
MY_SOCKET_TIMEOUT_MS,
-1, //intentos
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
getRequestQueue().add(req);
}
I played with the default parameters RetryPolicy, but always fails. I do not understand as the answer to my second request can be just the answer to the first, to call this second operation I need to go through the first onresponse The second call can never return the same data as the first, as seen in the log when I debug
Thanks !