Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在异步类中设置超时_Android_Asynchronous - Fatal编程技术网

Android 在异步类中设置超时

Android 在异步类中设置超时,android,asynchronous,Android,Asynchronous,我正在使用下面类似的异步类,但我不知道如何在异步类中设置时间 一段时间互联网连接很慢,然后异步类需要很多时间 private class GetServerChallans extends AsyncTask<String, Void, String> { @Override protected String doInBackground(String... urls) { String response = ""

我正在使用下面类似的异步类,但我不知道如何在异步类中设置时间

一段时间互联网连接很慢,然后异步类需要很多时间

private class GetServerChallans extends AsyncTask<String, Void, String> {
         @Override
            protected String doInBackground(String... urls) {
              String response = "";
              HttpEntity resEntity;
                try {
                    HttpClient httpclient = new DefaultHttpClient();
                    HttpPost httppost = new HttpPost("wwww...........");

                    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                    nameValuePairs.add(new BasicNameValuePair("token",strtoken));
                    nameValuePairs.add(new BasicNameValuePair("customer_code",strcustomer_code));
                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                    // Execute HTTP Post Request
                    HttpResponse responsePOST = httpclient.execute(httppost);
                     resEntity = responsePOST.getEntity();
                     response=EntityUtils.toString(resEntity);
                } catch (Exception e) {
                  e.printStackTrace();
                }

              return response;
            }

            @SuppressLint("DefaultLocale")
            @Override
            protected void onPostExecute(String result) {
                pd.dismiss();
                if(result!=null)
                {

                }

                }
            }

            @Override
            protected  void onPreExecute()
            {
                //pd = ProgressDialog.show(MyProfile.this, "","Please wait...");

            }
          }
请帮助我如何在异步类中使用超时


提前感谢

可能的副本,但在此如何添加HttpconnectionHttpConnectionParams.setConnectionTimeouthttppost.getParams,3000;HttpConnectionParams.setSoTimeouthttppost.getParams,5000;
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 5000);
HttpConnectionParams.setSoTimeout(httpParameters, 5000);
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);