I\'m running an android app that displays a webview on specific URL, I want to check if the application server I\'m accessing is alive and that I can view HTML, if failed I
The best way is to use an AsyncTask so your app doesn't freezes.
private class checkServer extends AsyncTask {
@Override
protected Void doInBackground(Integer... params) {
questionRunning = true;
//check if server is running
//now wait 10.000ms (10sec)
try {
Thread.sleep(params[0]);
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// Update your layout here
super.onPostExecute(result);
//Do it again!
new checkServer().execute(10000);
}
@Override
protected void onProgressUpdate(Integer... progress) {
}
}
How to call your AsynTask:
new checkServer().execute(10000);