我想在特定情况下暂停倒计时计时器。但在我的代码中,一旦启动,即使mIntheGym为false,它也不会停止。请在这个问题上帮助我。提前谢谢。
下面是我的代码。
TimerTask doAsynchronousTask1 = new TimerTask() {
@Override
public void run() {
handler1.post(new Runnable() {
public void run() {
try {
if (mIntheGym) {
mtextview.setText("counter starts");
mCountDownTimer1 = new CountDownTimer(mTimeLeftInMillis1, 500) {
@Override
public void onTick(long millisUntilFinished) {
mTimeLeftInMillis1 = millisUntilFinished;
updateCountDownText();
}
@Override
public void onFinish() {
}
}.start();
}
else {
mtextview.setText("stop counter");
if (mCountDownTimer1 != null) {
mCountDownTimer1.cancel();
}
}
} catch (Exception e) {
}
}
});
}
};发布于 2019-03-01 18:45:50
https://stackoverflow.com/questions/54942466
复制相似问题