如何停止位置管理器? [英] How to stop location manager?
本文介绍了如何停止位置管理器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
不知道为什么,但是有时位置管理器在关闭应用程序后仍然可以正常工作.
Don't know why, but sometimes LocationManager is still working also after closing application.
我在一个Activity中的onCreate-Methode中调用startGPS()(只有一个,我称之为StartActivity).
I call startGPS() in onCreate-Methode in one Activity (only one, let me call it StartActivity).
protected void startGPS(){
try {
lmanager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
lmanager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
lmanager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
} catch(Exception e) {
e.printStackTrace();
}
}
如果此活动将被破坏(因此,当应用程序关闭时),我将调用endGPS()
And if this activity will be destroyed (so, when application will be closed), I call endGPS()
public void endGPS(){
try {
lmanager.removeUpdates(this);
lmanager=null;
} catch(Exception e) {
e.printStackTrace();
}
}
一些想法,一些建议,我做错了什么?!
Some ideas, some suggestions, what have I done wrong?!
推荐答案
是否可能没有破坏您的活动?即:您按下了主页按钮.将您的GPS起点/终点移至onStart
和onPause
.
Is it possible your activity isn't being destroyed? i.e.: you hit the home button. Move your gps start/stop to onStart
and onPause
.
这篇关于如何停止位置管理器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文