Runnables will exit automatically when finished with their run()
method. If you are employing a loop to do some work, the solution that Jay Ho suggested will help exit from the loop cleanly. If you want to prevent the Handler
from executing the runnable (before it posts) you can use handler.removeCallbacksAndMessages(null)
1 to clear the queue. Placing it in onDestroy()
is your best bet. Otherwise, you're on your own. Once you've spawned a thread, you're at the mercy of the Android operating system to terminate it once its done.
Side note: I've run into problems like this before, and it's usually a call to a system service or the implementation of a Broadcast Listener or Alarm that mucks up the exit process.