Question: What if I have `handler.postDelayed` thread already under execution and I need to cancel it?

Answer: 
If you don't want to keep a reference of the runnable, you could simply call:

```
handler.removeCallbacksAndMessages(null);

```

[The official documentation](http://developer.android.com/reference/android/os/Handler.html#removeCallbacksAndMessages(java.lang.Object)) says:

> 
> ... If token is null, all callbacks and messages will be removed.
> 
> 
>
I had an instance where I needed to cancel a postDelayed while it was in the process of running, so the code above didn't work for my example. What I ended up doing was having a boolean check inside of my Runnable so when the code was executed after the given time it would either fire based on what the boolean value at the time was and that worked for me. 

```
 public static Runnable getCountRunnable() {
    if (countRunnable == null) {
        countRunnable = new Runnable() {
            @Override
            public void run() {
                if (hasCountStopped)
                    getToast("The count has stopped");
            }
        };
    }
    return countRunnable;
}

```

FYI - in my activity destroy I do use code suggested by the other developers, handler.removecallback and handler = null; to cancel out the handle just to keep the code clean and make sure everything will be removed.