summaryrefslogtreecommitdiffstats
path: root/core/java/android/os
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2014-01-31 16:29:16 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-01-31 16:29:16 +0000
commitff62e966b60bb20dc7c3384485816b1e7bf06057 (patch)
treed8eddacb561897b53a5c4e83be799f5624b79a87 /core/java/android/os
parented5d7a6f147c75c8af73328bdf816707b58afd90 (diff)
parent149510e010b46a445355a8d7fcdb8401125b92c3 (diff)
downloadframeworks_base-ff62e966b60bb20dc7c3384485816b1e7bf06057.zip
frameworks_base-ff62e966b60bb20dc7c3384485816b1e7bf06057.tar.gz
frameworks_base-ff62e966b60bb20dc7c3384485816b1e7bf06057.tar.bz2
am 149510e0: am b9f960e0: Merge "Fixed cancel() not working correctly"
* commit '149510e010b46a445355a8d7fcdb8401125b92c3': Fixed cancel() not working correctly
Diffstat (limited to 'core/java/android/os')
-rw-r--r--core/java/android/os/CountDownTimer.java15
1 files changed, 12 insertions, 3 deletions
diff --git a/core/java/android/os/CountDownTimer.java b/core/java/android/os/CountDownTimer.java
index 15e6405..58acbcf 100644
--- a/core/java/android/os/CountDownTimer.java
+++ b/core/java/android/os/CountDownTimer.java
@@ -16,8 +16,6 @@
package android.os;
-import android.util.Log;
-
/**
* Schedule a countdown until a time in the future, with
* regular notifications on intervals along the way.
@@ -56,6 +54,11 @@ public abstract class CountDownTimer {
private final long mCountdownInterval;
private long mStopTimeInFuture;
+
+ /**
+ * boolean representing if the timer was cancelled
+ */
+ private boolean mCancelled = false;
/**
* @param millisInFuture The number of millis in the future from the call
@@ -72,7 +75,8 @@ public abstract class CountDownTimer {
/**
* Cancel the countdown.
*/
- public final void cancel() {
+ public synchronized final void cancel() {
+ mCancelled = true;
mHandler.removeMessages(MSG);
}
@@ -80,6 +84,7 @@ public abstract class CountDownTimer {
* Start the countdown.
*/
public synchronized final CountDownTimer start() {
+ mCancelled = false;
if (mMillisInFuture <= 0) {
onFinish();
return this;
@@ -112,6 +117,10 @@ public abstract class CountDownTimer {
public void handleMessage(Message msg) {
synchronized (CountDownTimer.this) {
+ if (mCancelled) {
+ return;
+ }
+
final long millisLeft = mStopTimeInFuture - SystemClock.elapsedRealtime();
if (millisLeft <= 0) {