当定义为全局变量时,Android位置更新根本不起作用。。。怪虫

当定义为全局变量时,Android位置更新根本不起作用。。。怪虫,android,google-maps,gps,location,google-maps-android-api-2,Android,Google Maps,Gps,Location,Google Maps Android Api 2,非常奇怪的错误-我可以得到如下位置更新: LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 1, new LocationListener() { //On location changed code here } 但不是

非常奇怪的错误-我可以得到如下位置更新:

    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 1, new LocationListener() {

    //On location changed code here
    }
但不是这样:

    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 1, new LocationListener() {

    //On location changed code here
    }
全局变量:

   LocationManager lManager;
   LocationListener lListener;
在我的代码中:

   lManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

   lListener = new LocationListener() {

   //On location changed code goes here...
   }

   lManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 1, lListener);
为什么lListener/lManager是全球性的?第一,它们在其他地方的代码中用于其他位置轮询。第二,我需要全局设置,以便在暂停时正确退出locationservice

有人有什么想法吗?我被难住了


编辑:还有一件事:没有错误,但应用程序现在只获取一次位置,而不是每2秒轮询一次

这是什么错误显示没有错误,只是我有一些调试烤面包机,它可以检测位置何时发生了变化,我的应用程序的一部分在位置发生变化时再次激活自己的烤面包机。我没有看到这些。我应该补充的是,在应用程序第一次打开时检测到位置,但没有任何持续的轮询!你的gps启用了吗?是的,gps启用了,正如我上面所说的,我只获得一次位置信息,但仅此而已!没有固定的轮询。它不会自动轮询,您必须做一些事情才能获得位置更新。