Using Threading, Runnable and Message in Android
<p>This is my scenario. A class A implements Runnable. When user click a button, there will show a progress dialog and call the method <code>searchMap()</code> to search an address. The dialog dismisses after 10 seconds. I really misunderstand how to execute the <code>run()</code> method. this is my creepy code.</p>

<pre><code>public class AddLocationMapActivity extends MapActivity implements Runnable {
private ProgressDialog progressDialog;
private MyHandler myHandler; 
private Message msg;

@Override
public void run() {
    mapCurrentAddress();
}
public void mapLocation(View v) // click event here{
    progress();
    Thread thread = new Thread(this);
    thread.start();
}
private class MyHandler extends Handler{
@Override
public void handleMessage(Message msg) {    
    super.handleMessage(msg);
    switch(msg.what) {
        case NOT_OK_MESSAGE: // Fail
            alert(AddLocationMapActivity.this, message());
            progressDialog.dismiss();
        break;
        case OK_MESSAGE: // Success
            found(); // Point to the appropiate address
            progressDialog.dismiss();
        break;
        case EXPTION_MESSAGE: // Exception
            alert(AddLocationMapActivity.this, "Unexpected error");
            progressDialog.dismiss();
        break;
        }
    }
}
protected void mapCurrentAddress() {
    String addressString = addressText.getText().toString();
    Geocoder g = new Geocoder(this);
    List&lt;Address&gt; addresses;
    myHandler = new MyHandler();
    msg = myHandler.obtainMessage();
    try {
        addresses = g.getFromLocationName(addressString, 1);
        if (addresses.size() &gt; 0) {
            //address = addresses.get(0);
            msg.what = OK_MESSAGE;
            myHandler.sendEmptyMessage(OK_MESSAGE);

        } else {
            // show the user a note that we failed to get an address
            myHandler.sendEmptyMessage(NOT_OK_MESSAGE);
        }
    } catch (IOException e) {
        // show the user a note that we failed to get an address
        //e.printStackTrace();
        myHandler.sendEmptyMessage(EXPTION_MESSAGE);
    }
}
    private void progress() {
    progressDialog = ProgressDialog.show(this, 
            "Checking", "Contacting Map Server");
    Thread progressThread = new Thread();
    progressThread.start();
}
}
</code></pre>

<p>When click event occurs, the program fails with exception <strong>Uncaught Handler</strong></p>
