이 작업을 수행 할 수 없습니다. 문제는 리스너가 위치 검색을 완료했다는 스레드에 절대로 알리지 않습니다.Thread and Loop.prepare() issue
final ProgressDialog progress = new ProgressDialog(this);
progress.setTitle("Procurando");
progress.setMessage("Localizando o dispositivo.");
progress.show();
Thread thread = new Thread(new Runnable() {
public void run() {
// TODO Auto-generated method stub
GeoLocationHandler handler = new GeoLocationHandler();
try {
synchronized (handler) {
Looper.prepare();
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,handler);
handler.wait();
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
progress.dismiss();
mLocationManager.removeUpdates(handler);
double lat = mLocation.getLatitude();
double lng = mLocation.getLongitude();
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("http://maps.google.com/maps?saddr=" + lat + "," + lng + "&daddr=-22.858114, -43.231295"));
startActivity(intent);
}
}
thread.start();
다음은 클래스 구현 LocationListener입니다 :
private class GeoLocationHandler implements LocationListener {
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
mLocation = location;
notify();
}
}
해당 스레드를 시작할 위치. –
Bharat Sharma, 그냥 내 질문을 편집하고 thread.start() 추가, 그것은 run 메서드를 만드는 끝난 후 rigth입니다. 답변 해 주셔서 감사합니다. – jcmonteiro
스레드를 시작하는 것을 잊었습니다. –