如何设置时间在安卓 [英] How to set time out in android
本文介绍了如何设置时间在安卓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么办法来设置超时在Android中,如果从服务器特定时期内没有反应。
Is there any way to set time out in android, if there is no response from server for specific period.
推荐答案
以下是code,我用的时间不
Following is code that i used for time out
uri = new URI(url);
HttpGet method = new HttpGet(uri);
method.addHeader("Content-Type", "application/json");
HttpParams httpParameters = new BasicHttpParams();
int timeoutConnection = 60000;
HttpConnectionParams.setConnectionTimeout(httpParameters,
timeoutConnection);
int timeoutSocket = 65000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpResponse response = httpClient.execute(method);
HttpEntity responseEntity = response.getEntity();
statuscode = response.getStatusLine().getStatusCode();
将这个在try catch块,如果超过时间就会抛出异常
Put this in a try catch block and if exceeds the time it will throw the exception
这篇关于如何设置时间在安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文