Skip to content

Instantly share code, notes, and snippets.

@twaddington
Created September 6, 2012 20:42
Show Gist options
  • Save twaddington/3660229 to your computer and use it in GitHub Desktop.
Save twaddington/3660229 to your computer and use it in GitHub Desktop.
// Create a thread pool
private ExecutorService mThreadPool = Executors.newSingleThreadExecutor();
// Execute a new Runnable on a background Thread
Future f = pool.submit(new Runnable() {
public void run() {
while (true) {
// We're running!
Log.d(TAG, ".");
if (Thread.currentThread().isInterrupted()) {
// The runnable was cancelled!
Log.d(TAG, "Stopping!");
break;
}
}
}
});
// Cancel the runnable
f.cancel(true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment