0

I am facing the unidentified issue from several days that volley request becomes too slow when phone goes to sleep mode for some time and then return back to the app,i tried so many Retrypolicies given by volley, but none of them working correctly.below is my example code requesting volley to get data.

JsonObjectRequest movieReq = new JsonObjectRequest(
                    "MyURL" + session.getBusinessUserRegisterID(),
                    null,

                    new Response.Listener<JSONObject>() {
                        @Override
                        public void onResponse(JSONObject response) {

                            try {

                                String Connectionscount = response.getString("Connections");
                                String Expiredcountval = response.getString("Expired");
                                String Livecountval = response.getString("Live");
                                String NewCustomerscount = response.getString("NewCustomers");
                                String NewNotificationscount = response.getString("NewNotifications");
                                String SmsBalancecount = response.getString("SmsBalance");
                                String TotalCustomercount = response.getString("TotalCustomer");


                                 Newnotificationscount.setText(NewNotificationscount);
                                 Livecount.setText(Livecountval);
                                 Expiredcount.setText(Expiredcountval);
                                 Totalcustcount.setText(TotalCustomercount);
                                 Newcustcount.setText(NewCustomerscount);
                                 Myconnectionscount.setText(Connectionscount);
                                 Smscount.setText(SmsBalancecount);
                                ringProgressDialog.dismiss();
                                mSwipeRefreshLayout.setRefreshing(false);
                            } catch (JSONException e) {

                                e.printStackTrace();

                            }

                        }
                    }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {


                }

            });
            movieReq.setRetryPolicy(
                    new DefaultRetryPolicy(
                            10000,0,1f
                    )
            );

            AppController.getInstance().addToRequestQueue(movieReq);

First case placing second parameter of DefaultRetryPolicy greater than 0,it takes too long to give response

movieReq.setRetryPolicy(
                    new DefaultRetryPolicy(
                            10000,1,1f
                    )
            );

Second case placing Second parameter as 0 so i can be given error if volley doesn't responds for 10 seconds(I am showing alert to retry).

movieReq.setRetryPolicy(
                    new DefaultRetryPolicy(
                            10000,0,1f
                    )
            );
Hari krishna
  • 1,142
  • 1
  • 12
  • 29

1 Answers1

0

Try setting Priority high as :

@Override
public Priority getPriority() {
       return Priority.HIGH;
}
Basu
  • 763
  • 8
  • 27