![](/img/trans.png)
[英]does onLocationChanged of the LocationListener get called on initialization?
[英]LocationListener does not get killed
我有一个实现LocationListener的前台服务。 当服务被终止时,它将继续获得修复。 但是,这就是我在onDestroy()
所说的
@Override
public void onDestroy() {
Log.e(getPackageName(), "Destroying GPSservice");
super.onDestroy();
running = false;
stopForeground(true);
locationManager.removeUpdates(EventService.this);
locationManager = null;
}
有什么我想念的吗?
编辑
更多代码。 这在onCreate()
:
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String bestProvider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(bestProvider);
if (location != null) {
onLocationChanged(location);
}
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
3000L, 15.0f, this);
采用
locationManager.removeUpdates(Your_Location_Listener_instance);
代替
locationManager.removeUpdates(EventService.this);
有关更多信息,请参见doc public void removeUpdates(LocationListener侦听器)
我已经解决了问题。 事实证明, MyLocationOverlay
绑定到LocationSensorThread,而我从未关闭过它。 因此,这使GPS保持清醒状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.