我想从 URL 中获取一些数据,但服务器速度很慢...
所以每当我使用 volley 获取数据时,我都会得到 TimeOurError
,
无论如何我可以处理多长时间 volley 应该尝试获取数据,因为服务器很慢......它需要很少的时间
而且我还想不断运行这个请求来检查数据,我打算为此使用 Timer ...可以使用 Timer 来连续检查数据吗?
这是我现在的 volley 请求...它适用于其他 URL 的
public void checkData() {
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i("Response",response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.i("Response",error.toString());
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> map = new HashMap<String,String>();
map.put("deviceID","none");
return map;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
我需要连续调用这个函数(在应用程序内)
更新
我用过
tringRequest.setRetryPolicy(new DefaultRetryPolicy(
30000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
它奏效了,现在我想在我的应用程序中不断发出这个请求...最好的方法是什么?
最佳答案
您可以通过setRetryPolicy来控制volly请求的超时时间。
stringRequest.setRetryPolicy(new DefaultRetryPolicy(
YOUR_TIMEOUT_MS,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
看看this曲。
关于android - Volley : TimeOutError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47769722/