Hello,
I am writing a program. For that I need to include a functionality where I should get notified when the predetermined time is completed. For example if I set the time as 25 minutes I should be notified when 25 minutes are over.
Please tell me a way to do it
Comments
you can try something like this:
[color=Blue]Thread t = new Thread(new Runnable() {
long startTime = System.currentTimeMillis();
private volatile boolean timeUp = false;
final int END_TIME = 1;
long timePassed;
public void run() {
while(!timeUp){
timePassed = System.currentTimeMillis()-startTime;
update(timePassed);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
//you can handle the exception i you like
}
}
[color=Blue]System.out.println("time up"); [/color]
}
private void update(long timePassed){
if(timePassed >= END_TIME*60000) timeUp = true;
}
});
t.start();[/color]