开发者

How can you stop a progress dialog running when network access drops?

I have an app that goes out to a website to grab XML for processing. This process is in a separate thread and works fine when I have 3G or WiFi available. I also have code that checks signal before actually running the thread so it won't attempt with no connectivity.

During my testing, I walked into 开发者_StackOverflow社区a building that blocked all signal so the process started while I was outside and had signal but when I went inside the signal dropped and my Progress dialog just kept running, I had to manually shut the program down to get it to recover.

Is there a good way to deal with this without requiring the user to manually shut down the app if this situation happens?


Supply timeout parameters to your HttpClientand catch SocketTimeOutException

HttpParams httpParams=new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 5000);
HttpConnectionParams.setSoTimeout(httpParams, 5000);
HttpClient httpClient=new DefaultHttpClient(httpParams);
try {
    httpClient.execute(new HttpGet("http://myserver.xml"));
}
    catch(SocketTimeoutException ex){
        //Perform Timeout i.e. cancle progress dialog
    }
    catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜