jubin
jubin

Reputation: 97

Timer not stopped when i click back button in android

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

Sorry for my English.

Thanks in advance.

Upvotes: 1

Views: 2422

Answers (2)

ohm
ohm

Reputation: 293

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

Upvotes: 2

Matt Ball
Matt Ball

Reputation: 359966

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

CountDownTimer mTimer;

// snip...

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

Upvotes: 2

Related Questions