How can I pause one CountDown Timer when another one is running?

吃可爱长大的小学妹 提交于 2019-12-02 10:39:21

Create separate methods to start/pause/resume 24 second timer in your code. You need to store Your milliTillFinished of 24 seconds timer so you can pass it to resume timer method. You can pause 24 second timer on onTick() method of 4 second timer and resume it on onFinish() method.

To start timer:

   public void timerStart(long timeLengthMilli) {
    timer = new CountDownTimer(timeLengthMilli, 1000) {

        @Override
        public void onTick(long milliTillFinish) {
            milliLeft=milliTillFinish;
        }

To pause timer :

public void timerPause() {
    timer.cancel();
}

To resume timer:

private void timerResume() {
    timerStart(milliLeft);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!