我正試圖通過網絡上的線程加載信息。當沒有互聯網時,它會凍結很長一段時間,然後才發起異常或只是freeez。Android:是他們設置響應超時時間的一種方法= httpclient.execute(httppost);
有一種方法來設置//凍結該處或需要很長的時間來通過exceoption當沒有互聯網 一個超時是他們的一種方法來設置一個超時 響應= httpclient.execute(httppost);
代碼 HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(「http://besttechsolutions.biz/projects/bookclub/getevents.php」);
// FREEZES HERE或需要很長時間才能通過優秀時,當沒有互聯網 response = httpclient.execute(httppost);
responseBody = EntityUtils.toString(response.getEntity());
這可能會幫助你http://stackoverflow.com/questions/3000214/java-http-client-request-with-defined-timeout或這個http://stackoverflow.com/questions/9873810/using-apache- httpclient-how-to-set-timeout-on-a-request-and-response – 2013-03-12 12:57:06
或者只是檢查互聯網訪問http://stackoverflow.com/questions/1560788/how-to-check-internet-access-on -Android-InetAddress類 - 永不超時 – 2013-03-12 13:02:20