This is my thread:
public void run() {
Log.d("ConnectionThread","Starting Server Connection");
try {
while(isThereActivityRunning()) {
if(AppLoader.getIsInternetOn() == true)
{
Log.d("ConnectionThread", "Internet is On. Sending Http request");
results = sendGetMessage();
b.putString("results", results);
receiver.send(2, b);
}
else
Log.d("ConnectionThread","Internet is Off. Sleeping");
Thread.sleep(timeInterval);
}
I have the getIsInternetOn() function which is a static function in my AppLoader class (which extends Application).
For some reason whenever I change the value of the static boolean variable inside AppLoader to false, it doesn’t seem to affect on the code above.
The weird thing that inside my activity I’m able to change an view the same variable with the same functions:
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (AppLoader.getIsInternetOn())
AppLoader.setIsInternetOn(false);
else
AppLoader.setIsInternetOn(true);
}
});
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (AppLoader.getIsInternetOn())
internetStatus.setText("Internet is On");
else
internetStatus.setText("Internet is Off");
}
});
Try to add
volatilemodifier to your static variable.UPD:
It may happened because of caching the value for performance purposes.