In my application data comes from internet and I am trying to create a function that checks if a internet connection is available or not and if it isn\'t, it gives an alert
Maybe try this
handler.removeCallbacks(checkInternetConnection);
handler.postDelayed(checkInternetConnection, UPDATE_INTERVAL);
public Runnable checkInternetConnection = new Runnable() {
public void run() {
handler.postDelayed(checkInternetConnection, UPDATE_INTERVAL);
ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if(conMgr.getActiveNetworkInfo()!=null
&& conMgr.getActiveNetworkInfo().isAvailable()
&& conMgr.getActiveNetworkInfo().isConnected()){
alertOff();
}
else{
alertOn();
}
}
};