在我的應用我有一個後臺服務器和服務器類裏面我有定時器,內部定時器我有一個的LocationManager找到的位置:如何在Timer中使用LocationManager?
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new MyLocationListener();
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 5000, 10,
locationListener);
但在這裏我得到這個錯誤:
java.lang.runtimeexception can't create handler inside thread that has not called looper.prepare();
我這裏的問題如何使用定時器內的locationManager?
最好的答案感謝這就是我想:) –
請不要這樣做。在這裏看到第一個答案:http://stackoverflow.com/questions/7298375/get-activitys-reference-from-a-service 正確的解決方案要簡單得多。只需在服務中創建一個處理程序並使用其後處理方法即可。 –