是否可以实例化两个 LocationManager 对象?
我想要有两个单独的回调来调用 requestLocationUpdates(),每个回调监视不同的时间间隔(一个是时间,一个是距离)。这可能吗?或者我可以使用一个 LocationManager 实例并对其调用 requestLocationUpdates() 两次,声明一个单独的对象来实现 onLocationChanged() 作为其最后一个参数/参数?
I want to have two separate callbacks for calls to requestLocationUpdates(), each one monitoring for different intervals (one of time, one of distance). Is this possible? Or can I use one LocationManager instance and call requestLocationUpdates() on it twice, declaring a separate object to implement onLocationChanged() as its last arg/param?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以注册两次。例如,如果您想注册多个提供者,您甚至可以每次都使用相同的侦听器对象。
您只需为每个侦听器“removeUpdates”一次。所以如果你注册了同一个监听器两次,你只需要调用一次removeUpdates。
但是,如果您注册不同的时间间隔,两个侦听器仍可能获得所有更新。该接口不保证更新频率,传递的参数只是提示。它甚至可能因电话而异 - 在某些电话上,每个听众都可以按请求的频率获取更新,而在另一部电话上,两个听众都可以获取所有更新。
Yes, you can register twice. You can even use the same listener object each time if, for example, you want to register for more than one provider.
You only need to "removeUpdates" once for each listener. So if you have registered the same listener twice, you only need to call removeUpdates once.
However, it's possible that if you are registering for different intervals, that both listeners will still get all of the updates. The interface makes no guarantees about update frequency, and the parameters passed are just hints. It may even vary from phone to phone - on some phones each listener could get updates at the requested freqencies, and on another phone both listeners could get all of the updates.