我必须在这里做一个假设,因为代码显示不多!显然,您正在将
countDownTimer内部对象
onCreate用作内部类,这样无论何时都将触发计时器,
startTimer== true并且它将创建对象!我想最好创建一个的全局实例
CountDownTimer。
并以这种方式编写代码:
if(startTimer == true) { cdt = new CountDownTimer(120000, 1000) { public void onTick(long millisUntilFinished) { maxTime = (int) (millisUntilFinished / 1000); timer.setText(String.valueOf(maxTime)); } public void onFinish() { } }.start(); //start the countdowntimer}else{ cdt.cancel();}


