我有一个线程,试图获取用户的位置。handleMessage不叫
当收到位置“handler.sendMessage(msg)”被调用时,它返回true,但handleMessage永远不会被调用。
logcat中没有错误或警告。
代码:
public class LocationThread extends Thread implements LocationListener {
// ... Other (non-relevant) methods
@Override
public void run() {
super.run();
Looper.prepare();
mainHandler = new Handler(Looper.myLooper()) {
@Override
public void handleMessage(Message msg) {
// This method is never called
}
};
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 0, 0, this);
Looper.loop();
}
@Override
public void onLocationChanged(Location location) {
// SendMessage is executed and returns true
mainHandler.sendMessage(msg);
if (mainHandler != null) {
mainHandler.getLooper().quit();
}
locationManager.removeUpdates(this);
}
}
你写onlocation被改变检查的设备...... –
你尝试具有的handleMessage方法退出循环? – Fildor
我刚刚尝试过,但没有什么区别。 –