如何从Android中添加两次的LocationManager中删除LocationListener?

发布于 2024-10-08 01:45:41 字数 329 浏览 0 评论 0原文

如果我将 this 添加为 LocationListener 两次,如下所示

manager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,3,this);
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,3,this);

,只需删除 this 一次就足够了,如下所示

manager.removeUpdates(this);

If I add this as a LocationListener twice as follows

manager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,3,this);
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,3,this);

, would it be enough to just remove this once as follows

manager.removeUpdates(this);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

远昼 2024-10-15 01:45:41

是的,删除manager.removeUpdates(this);就足够了。正如 文档 所说

:使用给定的 LocationListener 进行当前活动的位置更新的任何当前注册。在此调用之后,此侦听器将不再发生更新。

Yes, removing manager.removeUpdates(this); is enough. As the documentation says:

Removes any current registration for location updates of the current activity with the given LocationListener. Following this call, updates will no longer occur for this listener.

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