我几天来面对这个身份不明的问题,当电话进入睡眠模式一段时间然后返回应用程序时,凌空请求变得太慢,我尝试了很多由凌空给出的重试政策,但没有一个正常工作.below是我的示例代码,请求凌空获取数据。
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);
将DefaultRetryPolicy的第二个参数设置为大于0的第一种情况,给出响应需要很长时间
movieReq.setRetryPolicy(
new DefaultRetryPolicy(
10000,1,1f
)
);
第二种情况将第二个参数设置为0,因此如果凌空没有响应10秒(我显示警告重试),我可以给出错误。
movieReq.setRetryPolicy(
new DefaultRetryPolicy(
10000,0,1f
)
);
答案 0 :(得分:0)
尝试将优先级设置为:
@Override
public Priority getPriority() {
return Priority.HIGH;
}