我有以下代碼可以執行通過asynctask進行xml下載,適用於android版本> 3的Android應用程序。如果網絡/互聯網連接良好,代碼工作很好。但是,如果互聯網連接不好,應用程序將強制關閉。我嘗試過投入不同類型的錯誤捕捉,但仍然無法解決低溫互聯網上的接近力量。Android應用程序強制關閉低溫互聯網連接
任何人有,我可以嘗試
private class DownloadWebPageXML extends AsyncTask<String, Void, InputStream> {
@Override
protected InputStream doInBackground(String... urls) {
Log.d("mylogitem", "AsyncTask started!");
InputStream content = null;
String myurl = urls[0];
AndroidHttpClient client = AndroidHttpClient.newInstance("Android");
HttpGet httpGet = new HttpGet(myurl);
try {
HttpResponse execute = client.execute(httpGet);
content = execute.getEntity().getContent();
} catch (Exception e) {
xmldownloaderror = e.getMessage();
Log.d("mylogitem", e.getMessage());
} finally {
Log.d("mylogitem", "Closing AndroidHttpClient");
client.close();
}
return content;
}
@Override
protected void onPostExecute(InputStream result) {
//do xml reader on inputstream
}
}