diff options
author | Jeff Brown <jeffbrown@google.com> | 2013-04-11 21:08:38 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-04-11 21:08:38 -0700 |
commit | dc5711eaef8662d5299f0088edf6e47fff77a872 (patch) | |
tree | 7f9c641870355e1e02d91670b1d1a89593bca0a3 /core | |
parent | c7512057feed983cf0eeb87f02f73426bfef5336 (diff) | |
parent | bf26c9cf87d3b83723fd12f4678b8b4286d8d08a (diff) | |
download | frameworks_base-dc5711eaef8662d5299f0088edf6e47fff77a872.zip frameworks_base-dc5711eaef8662d5299f0088edf6e47fff77a872.tar.gz frameworks_base-dc5711eaef8662d5299f0088edf6e47fff77a872.tar.bz2 |
am bf26c9cf: Merge "Ensure looper quits after all other messages are handled." into jb-mr2-dev
* commit 'bf26c9cf87d3b83723fd12f4678b8b4286d8d08a':
Ensure looper quits after all other messages are handled.
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/os/Looper.java | 12 | ||||
-rw-r--r-- | core/java/android/os/MessageQueue.java | 11 |
2 files changed, 16 insertions, 7 deletions
diff --git a/core/java/android/os/Looper.java b/core/java/android/os/Looper.java index 363a1bf..fa28765 100644 --- a/core/java/android/os/Looper.java +++ b/core/java/android/os/Looper.java @@ -201,8 +201,16 @@ public final class Looper { /** * Quits the looper. - * - * Causes the {@link #loop} method to terminate as soon as possible. + * <p> + * Causes the {@link #loop} method to terminate as soon as all remaining messages + * in the message queue that are already due to be delivered have been handled. + * However delayed messages with due times in the future may not be handled before + * the loop terminates. + * </p><p> + * Any attempt to post messages to the queue after {@link #quit} has been called + * will fail. For example, the {@link Handler#sendMessage(Message)} method will + * return false when the looper is being terminated. + * </p> */ public void quit() { mQueue.quit(); diff --git a/core/java/android/os/MessageQueue.java b/core/java/android/os/MessageQueue.java index e0d40c9..c058bfc 100644 --- a/core/java/android/os/MessageQueue.java +++ b/core/java/android/os/MessageQueue.java @@ -132,11 +132,6 @@ public final class MessageQueue { nativePollOnce(mPtr, nextPollTimeoutMillis); synchronized (this) { - if (mQuiting) { - dispose(); - return null; - } - // Try to retrieve the next message. Return if found. final long now = SystemClock.uptimeMillis(); Message prevMsg = null; @@ -170,6 +165,12 @@ public final class MessageQueue { nextPollTimeoutMillis = -1; } + // Process the quit message now that all pending messages have been handled. + if (mQuiting) { + dispose(); + return null; + } + // If first time idle, then get the number of idlers to run. // Idle handles only run if the queue is empty or if the first message // in the queue (possibly a barrier) is due to be handled in the future. |