views:

32

answers:

1

Hi,

I am using AsyncTask in my application.

The problem is that when server is down the AsyncTask throws an Interrupted exception. How to track that whether server is down or not.

`

HttpGet httpget = new HttpGet(urls[i]);

ResponseHandler<String> responseHandler = new BasicResponseHandler();

content = httpClient.execute(httpget, responseHandler);

`

This same problem also occurs when the handset is kept idle for some time then keyguard gets lock and I suppose that WI-FI also gets disabled. So, when I enable the keyguard and if my application is in foreground then it gives the same exception.

Can someone please let me know what should I do in order to remove this exception? Is there in solution to this.

Please let me know what can be done.

Regards

Sunil

A: 

Basically, before every url connexion, you could test the network availability by doing something like that :

if (connectivityManager.getActiveNetworkInfo() != null && connectivityManager.getActiveNetworkInfo().isAvailable()) {
//do your stuff
}

And you could also ping the server with a short timeout to check if the server is available.

Sephy
but this will check the network connectivity on device and not of the server. Can there be some other way out? To ping the server does not seem to be the solution. Can there be any other way for this?
sunil
Well, if you ping the server, you will know if it's down won't you?
Sephy
obviously, we will know the server is down. What I meant was it is not a proper solution. I have number of web services to be called from my code so for each web service I need to first ping the server and then call the web service. This doesn't seems to be the perfect solution
sunil