I’m trying to check for variable changes within a specified amount of time. For example I got a variable:
int downloadProgress = 0;
and I got some code which downloads a file and the var downloadProgress is being update to 1..2.3….5.6..7. until ..100 (download finishes).
Now I want to have a thread like the following:
Runnable checkNet = new Runnable(){
public void run(){
// check variable changes
}
};
that checks for changes in the variable downloadProgress within a specified amount of time say 20 seconds. If the variable doesn’t change for at least 20 seconds than I want to do something!
How could I utilize a timer to do this within a thread!!
you may use timer: http://developer.android.com/reference/java/util/Timer.html In this case you will not need a thread, because Timer imlies a thread
Here is example:
Source: http://dewful.com/?p=3