Gps location listener stop

风流意气都作罢 提交于 2019-12-11 06:39:45

问题


I am using this piece of code to stop gps locating the problem is that sometimes android kills my process starting it again... and the handle becomes invalid...making it impossible to stop the gps...how can i do this ?

here is the code:

lm.removeUpdates(locationListener);
locationListener = null;

回答1:


Try-

locationManager.removeUpdates(locListener);

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

And make sure you initialize your handler in onResume() and not onCreate()

Also put the above piece of code in onLocationChanged() since, as you've got the location, you don't need gps (for quite some time at least) as you said.



来源:https://stackoverflow.com/questions/9738980/gps-location-listener-stop

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!