Android VolleyBasicNetwork.logSlowRequests: HTTP response for request
Asked Answered
G

0

0

I have a problem with Volley GET request on slow network. Everytime I see BasicNetwork.logSlowRequests in my LogCat, my GET request is executed twice or more resulting multiple (2 or more) postings for 1 request. I already set the retry policy but It doesn't help.

This is my LogCat

03-16 01:31:35.674: D/Volley(5984): [19807] BasicNetwork.logSlowRequests: HTTP response for request=<[ ] http://[myserver]/api/places 0xfa7d0c33 NORMAL 1> [lifetime=3824], [size=313], [rc=200], [retryCount=0] 03-16 01:31:35.704: D/Volley(5984): [1] Request.finish: 3853 ms: [ ] http://[myserver]/api/places 0xfa7d0c33 NORMAL 1

my code:-

StringRequest strReq = new StringRequest(Request.Method.GET,
                url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        pd.dismiss();
                        getColorDetails.getColorresponse(response);
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        pd.dismiss();

                        if (error instanceof TimeoutError || error instanceof NoConnectionError) {

                            showSignOutAlertDialog(context, "TimeoutError");

                        } else if (error instanceof AuthFailureError) {
                            showSignOutAlertDialog(context, "AuthFailureError");

                        } else if (error instanceof ServerError) {

                            showSignOutAlertDialog(context, "ServerError");

                        } else if (error instanceof NetworkError) {

                            showSignOutAlertDialog(context, "NetworkError");
                        } else if (error instanceof ParseError) {

                            showSignOutAlertDialog(context, "ParseError");
                        }
                    }
                }) {

            /**
             * Passing some request headers
             * */
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<String, String>();
                //headers.put("Content-Type", "application/json; charset=utf-8");
                return headers;
            }

            @Override
            public String getBodyContentType() {
                return "application/json";
            }

            @Override
            protected Response<String> parseNetworkResponse(NetworkResponse response) {
                int mStatusCode = response.statusCode;
                System.out.println("Status code is===>"+mStatusCode);
                return super.parseNetworkResponse(response);
            }

        };

        strReq.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 2, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        AppController.getInstance().addToRequestQueue(strReq);
    }
Germanophile answered 16/6, 2016 at 7:23 Comment(8)
What's your volley version?Parcenary
compile 'com.navercorp.volleyextensions:volley-views:2.0.1' compile 'com.navercorp.volleyextensions:volley-requests:2.0.1' compile 'com.navercorp.volleyextensions:volley-caches:2.0.1'Germanophile
i am using this library files in build gradleGermanophile
Buddy, I have written a demo to debug your code. I got this log info. It just executed once as you see the log. Do you miss some pivotal detail?Parcenary
so what is the solution finally?Germanophile
I just used this code and replaced AppController.getInstance().addToRequestQueue(strReq); to MyVolley.getRequestQueue().add(strReq);. It worked normally.Parcenary
Let us continue this discussion in chat.Parcenary
Possible duplicate of Android Volley double post when have slow requestGlasshouse

© 2022 - 2024 — McMap. All rights reserved.