Thread
A Thread is a block of code that runs in parallel with the existing code of a class.
Example:
First, implement the Runnable interface.
implements Runnable
Second, declare an instance variable to refer to the Thread object.
Thread myThread;
Third, create the Thread object in a method or in onCreate.
myThread = new Thread(this);
myThread.start();
Fourth, write the run method that is declared in the Runnable interface.
public void run()
{
while (currentThread()==myThread)
{
try
{
Thread.sleep(500); // 500 ms
theView.postInvalidate(); // do whatever
}
catch (Exception e)
{
break;
}
}
} // end of method public void run()
Java Docs