Android倒计时器——CountDownTimer

Android倒计时器——CountDownTimer

说明

第一个参数是倒计时的时间
第二个参数是多长时间执行一次回调

/**
 * @param millisInFuture The number of millis in the future from the call to {@link #start()} until the countdown is done and {@link #onFinish()} is called.
 * @param countDownInterval The interval along the way to receive {@link #onTick(long)} callbacks.
 */
public CountDownTimer(long millisInFuture, long countDownInterval)

初始化

CountDownTimer timer = new CountDownTimer(Long.MAX_VALUE, Constants.LOOP_TIME) {

        @Override
        public void onTick(long millisUntilFinished) {
            // 倒计时当中的回调
        }

        @Override
        public void onFinish() {
            // 倒计时结束后的回调
        }
    };

开始倒计时

timer.start();

停止倒计时

timer.cancel();

posted on 2015-12-16 19:49  封起De日子  阅读(205)  评论(0编辑  收藏  举报

导航