Gps位置监听器停止

时间:2012-03-16 14:20:04

标签: android gps

我正在使用这段代码来阻止gps定位问题是有时候android会杀死我的进程再次启动它...并且句柄变得无效......让它无法阻止gps ...我怎么能这样做?

这是代码:

lm.removeUpdates(locationListener);
locationListener = null;

1 个答案:

答案 0 :(得分:2)

尝试 -

locationManager.removeUpdates(locListener);

        if (locListener != null) {
            locListener = null;
        }
        if (locationManager != null) {
            locationManager = null;
        }

并确保在onResume()而不是onCreate()

中初始化您的处理程序

同样将上面的代码放在onLocationChanged()中,因为你已经得到了位置,你不需要gps(至少在相当长的一段时间内)。