diff options
author | jl1990 <jlcarrasco1990@gmail.com> | 2013-08-07 17:39:22 +0200 |
---|---|---|
committer | Narayan Kamath <narayan@google.com> | 2014-01-30 13:46:44 +0000 |
commit | 3cd12a515562b278c05dff88324f254995a60e9e (patch) | |
tree | eccb5d7ba9244dfa27f6c362c51525a0189d14ca /core/java/android/os | |
parent | 54190ec8307ebb83d02b7d9b8edc80a042792de6 (diff) | |
download | frameworks_base-3cd12a515562b278c05dff88324f254995a60e9e.zip frameworks_base-3cd12a515562b278c05dff88324f254995a60e9e.tar.gz frameworks_base-3cd12a515562b278c05dff88324f254995a60e9e.tar.bz2 |
Fixed cancel() not working correctly
The method handleMessage(Message msg) from mHandler variable was
not checking if the timer was cancelled, so
sendMessageDelayed(obtainMessage(MSG), delay) was keeping the
timer alive. The patch simply adds a boolean and checks if the
CountDownTimer was cancelled before calling
sendMessageDelayed(obtainMessage(MSG), delay)
bug: https://code.google.com/p/android/issues/detail?id=58668
Change-Id: Ic6bbb9d33a3616f8503db222513cc14ad2270cb8
Signed-off-by: jl1990 <jlcarrasco1990@gmail.com>
Diffstat (limited to 'core/java/android/os')
-rw-r--r-- | core/java/android/os/CountDownTimer.java | 15 |
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) { |