From 820e3dd74a4a1db0784cf03c553090c31b111638 Mon Sep 17 00:00:00 2001 From: Jake Wharton Date: Tue, 2 Jan 2018 22:18:24 -0500 Subject: Add overload to postDelayed which accepts a token. This adds overload parity with postAtTime. Test: none Bug: 71546743 Change-Id: I50936c7ffd5e8512dc865863fe8d4c9fb228a8a9 --- api/current.txt | 1 + core/java/android/os/Handler.java | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/api/current.txt b/api/current.txt index 892584661084..9741fbc0db7f 100644 --- a/api/current.txt +++ b/api/current.txt @@ -31570,6 +31570,7 @@ package android.os { method public final boolean postAtTime(java.lang.Runnable, long); method public final boolean postAtTime(java.lang.Runnable, java.lang.Object, long); method public final boolean postDelayed(java.lang.Runnable, long); + method public final boolean postDelayed(java.lang.Runnable, java.lang.Object, long); method public final void removeCallbacks(java.lang.Runnable); method public final void removeCallbacks(java.lang.Runnable, java.lang.Object); method public final void removeCallbacksAndMessages(java.lang.Object); diff --git a/core/java/android/os/Handler.java b/core/java/android/os/Handler.java index 3ca1005b8c98..5c5e351d2eeb 100644 --- a/core/java/android/os/Handler.java +++ b/core/java/android/os/Handler.java @@ -388,6 +388,8 @@ public class Handler { * The runnable will be run on the thread to which this handler is attached. * * @param r The Runnable that will be executed. + * @param token An instance which can be used to cancel {@code r} via + * {@link #removeCallbacksAndMessages}. * @param uptimeMillis The absolute time at which the callback should run, * using the {@link android.os.SystemClock#uptimeMillis} time-base. * @@ -429,6 +431,32 @@ public class Handler { return sendMessageDelayed(getPostMessage(r), delayMillis); } + /** + * Causes the Runnable r to be added to the message queue, to be run + * after the specified amount of time elapses. + * The runnable will be run on the thread to which this handler + * is attached. + * The time-base is {@link android.os.SystemClock#uptimeMillis}. + * Time spent in deep sleep will add an additional delay to execution. + * + * @param r The Runnable that will be executed. + * @param token An instance which can be used to cancel {@code r} via + * {@link #removeCallbacksAndMessages}. + * @param delayMillis The delay (in milliseconds) until the Runnable + * will be executed. + * + * @return Returns true if the Runnable was successfully placed in to the + * message queue. Returns false on failure, usually because the + * looper processing the message queue is exiting. Note that a + * result of true does not mean the Runnable will be processed -- + * if the looper is quit before the delivery time of the message + * occurs then the message will be dropped. + */ + public final boolean postDelayed(Runnable r, Object token, long delayMillis) + { + return sendMessageDelayed(getPostMessage(r, token), delayMillis); + } + /** * Posts a message to an object that implements Runnable. * Causes the Runnable r to executed on the next iteration through the -- cgit v1.2.3-59-g8ed1b