Android 截击:时间错误

Android 截击:时间错误,android,android-volley,Android,Android Volley,我想从URL获取一些数据,但服务器速度非常慢。。。 因此,每当我使用截击来获取数据时,我都会得到TimeOurError, 在服务器运行缓慢的情况下,我是否可以处理截击需要多长时间才能获取数据…这只需要很少的时间 我还想不断地运行这个请求来检查数据,我计划使用定时器来检查数据……使用定时器来连续检查数据可以吗 这是我现在的截击请求…它适用于其他URL public void checkData() { StringRequest stringRequest = new StringReq

我想从URL获取一些数据,但服务器速度非常慢。。。 因此,每当我使用截击来获取数据时,我都会得到
TimeOurError
, 在服务器运行缓慢的情况下,我是否可以处理截击需要多长时间才能获取数据…这只需要很少的时间 我还想不断地运行这个请求来检查数据,我计划使用定时器来检查数据……使用定时器来连续检查数据可以吗

这是我现在的截击请求…它适用于其他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);

}
它成功了,现在我想在我的应用程序中不断地提出这个请求…什么是最好的方法

StringRequest request = new StringRequest(Request.Method.GET, requestURL, stringListener, errorListener);
        request.setRetryPolicy(new DefaultRetryPolicy(
                30000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

        addToRequestQueue(request);

//此代码将有助于增加批量请求的时间。请尝试此代码。

您可以设置策略来控制批量请求超时时间

stringRequest.setRetryPolicy(new DefaultRetryPolicy(
        YOUR_TIMEOUT_MS, 
        DefaultRetryPolicy.DEFAULT_MAX_RETRIES, 
        DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

看看Qus。

添加这4行,将android截击时间增加到60秒

StringRequest myRequest   

JsonObjectRequest myRequest


这段代码将有助于增加截击请求的时间。试试它。并解决截击:TimeOutError

stringRequest.setRetryPolicy(new DefaultRetryPolicy(
    30000,DefaultRetryPolicy.DEFAULT_MAX_RETRIES,DefaultRetryPolicy.DEFAULT_BACKOFF_MULT
));

尝试一下,谢谢。它工作得很好,现在你能告诉我什么是在应用程序中连续调用此请求的最佳方式吗?尝试创建一个方法,通过发送requestURL、字符串侦听器和错误侦听器来调用volley,并调用方法cont。我将用它实现什么?你能举个好例子吗?通过编辑你的答案
RetryPolicy policy = new DefaultRetryPolicy(60000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
myRequest.setRetryPolicy(policy);

RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(myRequest);
stringRequest.setRetryPolicy(new DefaultRetryPolicy(
    30000,DefaultRetryPolicy.DEFAULT_MAX_RETRIES,DefaultRetryPolicy.DEFAULT_BACKOFF_MULT
));