Specifying the Code to Run on a Thread

Define a task that executes on a separate thread, by defining a class that implements the Runnable interface.

Thread and Runnable are the basis of powerful Android classes such as HandlerThread, AsyncTask, and IntentService. Thread and Runnable are also the basis of the class ThreadPoolExecutor. This class automatically manages threads and task queues, and can even run multiple threads in parallel.