![](/img/trans.png)
[英]Android application crashing on 3G, slow connection, but works over WIFI
[英]Android app crash on 3G slow connection but works fine over wifi
我有一個小型的android應用程序,該應用程序基本上執行http調用以檢索一些網頁信息,並在本地解析它以用於顯示。
它在wifi上工作正常。 但是,在提交http查詢后,該應用在3G上隨機崩潰(並非始終如此,但足夠頻繁)。 通常,我能夠重新啟動該應用程序,嘗試執行相同的任務,它將按預期運行。 我有點想調試這個問題。 是互聯網連接速度慢引起的嗎? 丟包? 我可以放入哪種檢查代碼來防止這種情況發生?
一些示例代碼:
HttpClient client = new DefaultHttpClient();
HashMap<String, String[]> hmSearchResults = null;
HttpGet getMethod = new HttpGet(url);
try {
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String resultPage = client.execute(getMethod, responseHandler);
// I am think the error is here if resultPage == null due to
// whatever reason, is there any check I can put around
// client.execute?
hmSearchResults = ParseHtml.getSearchResultText(resultPage, numRequestResults);
} catch (Throwable t) {
Utility.showToast(this,"Request failed: " + t.toString());
}
您是通過活動還是服務來運行它? 在我自己的應用程序中,僅當我從服務運行代碼時才會遇到此問題。 它可以在wifi上完美運行,但在3G上崩潰,並且從不崩潰。
我可以找到用於解決服務崩潰的唯一解決方法如下:
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.