从位置侦听器调用方法似乎不起作用!

发布于 2024-10-20 01:11:21 字数 896 浏览 4 评论 0原文

我已经实现了一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑,眼淚并存 2024-10-27 01:11:21

根据对该问题的评论,问题不在于代码永远不会运行,而是调试器以某种方式无法允许它单步执行。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文