【问题标题】:What is the best solution for collecting location info in the background?在后台收集位置信息的最佳解决方案是什么?
【发布时间】:2011-11-04 15:27:32
【问题描述】:

我想制作一个应用程序,每 30 分钟获取一次手机位置并将其保存到数据库(并传输到网络服务器)。

应用程序应该在后台运行几个小时,而用户可以用他的手机做其他事情(游戏、通话...)

有人可以建议这个项目的最佳解决方案是什么吗? (服务?AlermManager?)

【问题讨论】:

标签: android


【解决方案1】:

就我而言,Android - Service 对我来说是最好的解决方案。

服务示例 - ServicesDemo - Using Android Services

Define and consume your own service .

编辑:看看这个SO问题Running a service to get location details

【讨论】:

  • 感谢您的回复!会看看的!
【解决方案2】:

一个很好的方法是通过registering a pending Intent 而不是位置监听器。

这可能导致您的应用在等待新位置时没有运行。待处理的 Intent 应该指向 intent service,这样您在收到新位置后就无需考虑在后台工作。

如果您不需要更多位置更新,您只需unregister the intent

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-24
    • 2012-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多