Wait N Seconds to Do Something, When User Tap During This period, Cancel it
<p>I want to achieve the following task:</p>

<pre><code>if (already wait for 3 seconds) {
    // do the task
} else {
    // keep waiting ...
    if (user tap the UI widget) {
        return; // do nothing
    }
}
</code></pre>

<p>At first, I want to use handler, use <code>sendMessageDelayed</code> (Message msg, long delayMillis) to enqueue a message into the message queue after all pending messages before (current time + delayMillis). when the user taps, I <code>removeMessages</code>(int what). But it does not work. </p>

<p>Does anybody know how to achieve this? Thanks.</p>

<p>========================================================</p>

<p>Thanks all.</p>

<p>I found this solution works well, I was too careless to use the wrong Handler reference to <code>removeMessages</code>, so, it did not work.</p>
