暂停CountDown计时器Android

时间:2014-03-03 19:21:09

标签: android countdown

我正在制作一款具有倒计时功能的Android游戏。倒计时效果很好,但问题是当我暂停游戏时(我停止绘制表面视图),倒计时继续进行。

new CountDownTimer(60000, 1000) {
    public void onTick(long millisUntilFinished) {       
        timer = String.valueOf(millisUntilFinished / 1000);
        invalidate();
    }

    public void onFinish() {
    }
}.start();

如何暂停倒计时?

1 个答案:

答案 0 :(得分:0)

您可以通过制作变量计时器

来实现
 static int timer = 60000;

将此作为论据:

CountdownTimer ct = new CountdownTimer(timer,1000){
     Update your timer variable every time the countdown ticks.
     Timer = timer-1000;
     .
     .

}

现在,只要您想暂停计时器

ct.cancel();

通过调用

随时启动
ct.start;