How to run thread + Handler in android


How to run thread + Handler in android



First Run the Thread------------------------------------



---------------------------------------------------------------
private void findLocation(final String locationName)
{
Thread thrd = new Thread()
{
public void run()
{
try {
addressList = geoCoder.getFromLocationName(locationName, 5);

// After completing the thread,call Handler --------------------------------------------------------
----------------------------------------------------------------------------------------------------

uiCallback.sendEmptyMessage(0);

} catch (Exception e) {


}
}
};
thrd.start();

}


//Handler runs after completing thread--------------------------------------------------------------
----------------------------------------------------------------------------------------------------


private Handler uiCallback = new Handler()
{
@Override
public void handleMessage(Message msg)
{
progDialog.dismiss();
if(addressList!=null && addressList.size()>0)
{
int lat = (int)(addressList.get(0).getLatitude()*1000000);
int lng = (int)(addressList.get(0).getLongitude()*1000000);
GeoPoint pt = new GeoPoint(lat,lng);
mapView.getController().setZoom(15);
mapView.getController().setCenter(pt);
}
else
{
Dialog foundNothingDlg = new
AlertDialog.Builder(GeocodingDemoActivity.this)
.setIcon(0)
.setTitle("Failed to Find Location")
.setPositiveButton("Ok", null)
.setMessage("Location Not Found...")
.create();
foundNothingDlg.show();
}
}
};