开发者

Timer not stopped when i click back button in android

开发者 https://www.devze.com 2023-02-24 22:34 出处:网络
I am using the countdown timer but when i click back button the timer continues.Can any body tell 开发者_JAVA技巧me how can i stop when i click my phone back button not my application back button.

I am using the countdown timer but when i click back button the timer continues.Can any body tell 开发者_JAVA技巧me how can i stop when i click my phone back button not my application back button.

Sorry for my English.

Thanks in advance.


How about overriding the onBackPressed() method? Something like this (untested):

CountDownTimer mTimer;

// snip...

@Override
public void onBackPressed() {
    mTimer.cancel();
}


You need to cancel the timer. Call timer.cancel() when you press the back button. E.g. in the onPause() method.

0

精彩评论

暂无评论...
验证码 换一张
取 消