我正在创建一个类似于内置短信应用的应用。
我需要什么:
- 始终在后台运行的服务
- 每 5 分钟一次。该服务检查设备的当前位置并调用网络服务
- 如果满足某些条件,服务应生成通知(就像 SMS 应用程序一样)
- 当点击通知时,用户被带到应用程序(就像短信应用程序一样)
- 安装应用后,应启动服务
- 设备重启后,服务应该会启动
我尝试过的:
- 运行正常的服务,直到 Android 终止服务
- 使用 AlarmManager 制作 5 分钟。对服务的间隔调用。但我无法完成这项工作。
最佳答案
a service that is always running in the background
这是not possible正如您所发现的那样,在任何真正意义上的术语中。也是bad design .
every 5 min. the service checks the current location of the device and calls a web service
使用AlarmManager
。
using the AlarmManager the make the 5 min. interval call to a service. But I was not able to make this work.
这里是 sample project显示如何使用一个,以及使用 WakefulIntentService
所以你在尝试做整个 Web 服务的时候保持清醒。
如果您仍然遇到问题,请针对您在使用 AlarmManager
时遇到的具体问题提出新问题。
关于android - 如何始终在后台运行服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2566350/