Reputation: 595
I am developing an android app, which uses the Timer. I want to create a timer that count example to 3 min, after that I want to create function or using true to check if the time go to 3 min or not like :
if (time < 3 min ){do something }
thanks for help
Upvotes: 0
Views: 546
Reputation: 304
this might help you ... You can also use AlarmManager to do a job after intervals ...
Upvotes: 0
Reputation: 1385
Something like this?
Timer timer = new Timer(); //init the timer
Handler handler = new Handler();
int counter = 0; //counter to indicate the total second whenever timer fire
timerTask task = new timerTask();
timer.scheduleAtFixedRate(task,500,1000); //(which task to run,forget the usage try google, looping must be milisecond eg.1000 = 1 second)
private class timerTask extends TimerTask{
@Override
public void run() {
handler.post(new Runnable() {
@Override
public void run() {
counter++;
if(counter >= 90){ //check wether it is 90 second (1 and half minutes)
//do something
}
}
});
}
}
Upvotes: 1