I'd like to pause countdown timer in specific condition. But in my code, once it starts, it never stop even when mIntheGym is false. Please help me on this issue. Thanks in advance.
Here is my code below.
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) {
}
}
});
}
};