0
votes

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 !

1

1 Answers

0
votes

I donĀ“t understand because some guy send me a negative vote...

I fixed my problem. Maybe can help my solution to someone. Volley have a cache When you add a request to the queue, you can disable cache https://developer.android.com/intl/es/training/volley/simple.html For this reason when I debug, my app work fine, the cache should was deleted for volley by time(1-2 second into requests) , and when I run my app the cache work and return always the first response. You can disable the cache , this is a example Disable Volley cache management