Than the system comes with CountDownTimer made the following enhancements:
- Support WeakReference the listener, to avoid memory leaks.
- Self-correction heartbeat error, there will not be more and more problems heartbeat interval, to avoid jumping seconds phenomenon.
- The release () method can release the strongly referenced listener.
private QuartzCountdown mCountdown;
public void startCountdown() {
mCountdown = new QuartzCountdown.QuartzCountdownBuilder()
.durationMs(60000).intervalMs(1000).listener(this, true).build();
mCountdown.start();//start count down
}
...
@Override
public void onTic(QuartzCountdown quartzCountdown, long remainMs) {
//invoke every intervalMs
int remainSecond = Math.round(remainMs / 1000f)
}
@Override
public void onStopped(QuartzCountdown quartzCountdown) {
//invoke after durationMs or stop()
}
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile 'com.github.itvincent-git:quartz-countdown:1.0.0'
}