对同一提供商使用多个 LocationManager requestLocationUpdates(...)
我的应用程序后台运行了一个位置服务,其中 requestLocationUpdates(LocationManager.GPS_PROVIDER, 5*60*1000 , 1, this)
每 5 分钟获取一次位置更新。在一项给定的活动中,我需要更频繁的更新。我可以创建另一个 LocationManager 并在此活动中为同一提供程序注册另一个 requestLocationUpdates 侦听器,如下所示?
locManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 100, 1, this);
我已经尝试过了,它似乎有效,但我想确保它不会与后台服务产生任何冲突......
I've got a location service running in background of my app with requestLocationUpdates(LocationManager.GPS_PROVIDER, 5*60*1000 , 1, this)
to get a location update every 5 min. In one given activity I need much more frequent updates. Can I create another LocationManager and register another requestLocationUpdates listener for the same provider in this activity as shown below?
locManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 100, 1, this);
I've tried and it seems to work, but I'd like to be sure that it won't create any conflict with the background service...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
别担心。在后台,只有一个 GPS 位置提供程序实例以您设置的两次频率的最小值运行。
值得关注的一点是您设置的 100 毫秒间隔。我认为 1 秒更新是大多数 GPS 芯片组可以设置的最小间隔。
Don't worry about it. Under the hood there is only one GPS location provider instance running with a frequency of minimum of those two time that you have set.
A point of concern is the 100ms interval that you have set. I think that 1 sec updates is the least interval that you can set for most GPS chipsets.