从位置侦听器调用方法似乎不起作用!
我已经实现了一个 locationListener,并且希望每次更改位置时都从 onLocationChanged 方法中调用一个方法。
位置侦听器作为服务中的类实现。当应用程序位于前台时,一切似乎都工作正常,但当它没有收到更新时,我调用该方法,但在调试后我意识到,由于某种原因,它没有进入该方法。
我的 LocationListener:
public class MyLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
Log.d("----ADS SERVICE LOCATION LISTENER-------", "LOCATION UPDATE");
contactServer(location);
}
public void onStatusChanged(String s, int i, Bundle b) {
}
public void onProviderDisabled(String s) {
}
public void onProviderEnabled(String s) {
}
}
这就是它被卡住的地方...没有进入方法的主体
private void contactServer(Location location){
有什么想法为什么会发生这种情况吗?我可以将所有代码放在 onLocationChanged 方法中,但它实际上应该放在一个单独的方法中,因为它很长并且并不真正相关!
I've implemented a locationListener and I want every time the location is changed to call a method from within the onLocationChanged method.
The location listener is implemented as a class within a service. Everything seems to be working fine when the app is in the foreground but when its not I receive updates I call the method but I realised after debugging that it doesnt get inside the method for some reason.
My LocationListener:
public class MyLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
Log.d("----ADS SERVICE LOCATION LISTENER-------", "LOCATION UPDATE");
contactServer(location);
}
public void onStatusChanged(String s, int i, Bundle b) {
}
public void onProviderDisabled(String s) {
}
public void onProviderEnabled(String s) {
}
}
And this is where it gets stuck...Doesnt go through to the body of the method
private void contactServer(Location location){
Any ideas why this is happening? I could put all the code in the onLocationChanged method but it should really be in a separate method as its very long and not really relevant!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据对该问题的评论,问题不在于代码永远不会运行,而是调试器以某种方式无法允许它单步执行。
As per comments on the question, the problem is not that code never runs but that the debugger somehow failed to allow it to be stepped through.