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);