56.6 Creating a New Thread
In order to create a new thread, the code to be executed in that thread needs to be placed within the run() method of a Runnable instance. A new Thread object then needs to be created, passing through a reference to the Runnable instance to the constructor. Finally, the start() method of the thread object needs to be called to start the thread running. To perform the task within the buttonClick() method, therefore, the following changes need to be made:
public void buttonClick(View view) {
Runnable runnable = new Runnable() {
public void run() {
long endTime = System.currentTimeMillis() + 20 * 1000;
while (System.currentTimeMillis() < endTime) {
&...