Hi i'm trying to update the UI from a background thread. I'm setting the selection of a Radio Button programetically but strangely it wouldnt update the UI when I run the app. But when I debug the application step by step the UI updates itself which is very strange to me. following is the code I am using to do it.
As post runnable returns a boolean and it seems to return true about the update but it doesnt update the UNI which is very strange.
Thread
_internetConenctivityThread = new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try
{
CheckInternetConnectivity(conManager);
Thread.sleep(30000);
}
catch(Exception ex)
{
Log.d("_internetConnectivityThread", "Exception while checking connectivity: " + ex.getMessage());
}
}
});
_internetConenctivityThread.start();
Method for the Check
private void CheckInternetConnectivity(ConnectivityManager cm)
{
try
{
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnected()) {
mParent.connectivity.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
// Updating Status Monitor for connectivity
mParent.connectivity.setChecked(true);
}
});
}
else
{
mParent.connectivity.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
// Updating Status Monitor for connectivity
mParent.connectivity.setChecked(false);
}
});
}
}
catch(Exception ex)
{
ex.getMessage();
}
}