Skip to content

Instantly share code, notes, and snippets.

@durgaswaroop
Last active December 28, 2016 19:25
Show Gist options
  • Save durgaswaroop/8c5d546d0372472bf97f9c54483f0cf9 to your computer and use it in GitHub Desktop.
Save durgaswaroop/8c5d546d0372472bf97f9c54483f0cf9 to your computer and use it in GitHub Desktop.
Serial Countdown timers in Android
private class MyTimer extends CountDownTimer {
public MyTimer(final long millisInFuture, final long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onTick(final long milliSecondsStillLeftToFinish) {
long seconds = milliSecondsStillLeftToFinish / 1000;
long mins = seconds / 60;
tvTimer.setText(String.valueOf(mins + ":" + String.valueOf(seconds - mins * 60)));
}
@Override
public void onFinish() {
myTimer.cancel();
queue.remove()
if(queue.size != 0) { // condition to check if another timer should be started
if(condition1) {
// Enters these if blocks but the timers are not starting
MyTimer myTimer1 = new MyTimer(10 * 1000, 1000);
myTimer1.start();
}
else if(condition2) {
// Enters these if blocks but the timers are not starting
MyTimer myTimer1 = new MyTimer(1 * 1000, 1000);
myTimer1.start();
}
else if(condition3) {
// Enters these if blocks but the timers are not starting
MyTimer myTimer1 = new MyTimer(4 * 1000, 1000);
myTimer1.start();
}
}
else {
tvTimer.setText("Done!");
}
}
}
private MyTimer myTimer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment