Reputation: 643
I am a new develop of Android. I want to create an Application about time. The question is "how to call method every 30 second?" Example: Every 30 second the application will send some message.
I do not know how to do it firstly, I use this function
time = new CountDownTimer(10000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
if(isDistanceStable()){
Toast.makeText(ChangeStatus.this, "Your speed is normal.", 3).show();
}else{
Toast.makeText(ChangeStatus.this, "Your speed is abnormal.", 3).show();
callManualRed();
}
}
@Override
public void onFinish() {
// TODO Auto-generated method stub
time.cancel();
//intervalCheckDistance();
}
}.start();
}
but how to call it every 30 second. Please give me an example or some solutions to solve it. Thank you very much and Sorry with my English
Upvotes: 0
Views: 2042
Reputation: 1521
cdt = new CountDownTimer(30000, 30000) {
public void onTick(long millisUntilFinished) {
// Method
}
public void onFinish() {
cdt.start(); // Call Again After 30 seconds
}
}.start();
Remember to call cdt.cancel();
when you want to end the timer
Upvotes: 2