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);
    }
Krish
  • 4,166
  • 11
  • 58
  • 110
  • What's your volley version? – JohnWatsonDev Jun 16 '16 at 07:38
  • 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' – Krish Jun 16 '16 at 07:45
  • i am using this library files in build gradle – Krish Jun 16 '16 at 07:45
  • Buddy, I have written a demo to debug your code. I got this [log info](http://pastebin.com/raw/dQuG061U). It just executed once as you see the log. Do you miss some pivotal detail? – JohnWatsonDev Jun 16 '16 at 10:04
  • so what is the solution finally? – Krish Jun 16 '16 at 10:05
  • I just used this [code](https://github.com/naver/volley-extensions/blob/master/samples/demos/src/main/java/com/navercorp/volleyextensions/sample/demos/application/volley/MyVolley.java) and replaced `AppController.getInstance().addToRequestQueue(strReq);` to `MyVolley.getRequestQueue().add(strReq);`. It worked normally. – JohnWatsonDev Jun 16 '16 at 10:08
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/114831/discussion-between-johnwatsondev-and-krish). – JohnWatsonDev Jun 16 '16 at 10:09
  • Possible duplicate of [Android Volley double post when have slow request](https://stackoverflow.com/questions/22428343/android-volley-double-post-when-have-slow-request) – Andrea Motto Mar 23 '18 at 01:22

0 Answers0