如何实现更新服务在后台运行?
我目前正在为 Android 操作系统开发一个显示一些数据的应用程序。为了确保此数据是最新的,应用程序需要不时从远程服务器获取更新。 由于数据变化不频繁,因此应每周更新一次。我想让用户能够选择更新的工作日和白天(并且可以选择完全禁用此功能)。
问题是:即使用户此时没有使用手机,即使手机当前处于睡眠状态,即使手机最近重新启动并且应用程序尚未启动,也应该执行此更新。
我首先想到的是一个远程服务,它在系统启动时启动,确定运行更新的时间,设置计时器,然后等待/睡眠计时器触发。
现在,我被告知我应该使用闹钟计时器或某种处理程序......我对这个主题的了解越多,似乎存在越多的方法来做到这一点。
现在,我有点迷失哪种方法最适合我......所以这就是我需要的:
我想这里有人知道 Android 版的“newsrob”吗?我想要实现的与 newsrob-updateservice 几乎相同。
I'm currently working on an app for the Android OS that displays some data. To ensure this data is up-to-date, it is required that the app fetches updates from a remote server from time to time.
As the data does not change very often, this update should be carried out once per week. I want to give the user the ability to choose the weekday and daytime of the update (and optionally disable this feature completely).
The thing is: this update should be carried out even when the user is not using the phone at this moment, even when the phone is currently sleeping and even when the phone has been rebooted recently and the app hasn't been started yet.
The first thing I thought of was a remote service that starts at system boot, determines the time when to run the update, sets a timer and then waits/sleeps for the timer to fire.
Now, I was told I should rather use alarm timers or some kind of handlers... the more I read about this topic, the more ways to do this seem to exist.
Now, I'm a bit lost which method is the best for me... so here is what I need:
I think anyone here knows "newsrob" for android? What I want to realize is pretty much the same as the newsrob-updateservice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Android 服务 + 广播接收器 + 警报服务将解决您的目的 -
您的服务将从广播接收器调用,并且在广播接收器中您应该注册各种事件 - BOOT_RECEIVER 、 ACTION_USER_PRESENT ,它将处理您的警报重置和更新任务。
谢谢。
Android Service + Broadcast Receiver + Alarm Service will solve your purpose -
Your service will be invoked from BroadCast Receiver and In Broadcast receiver you should register for various events - BOOT_RECEIVER , ACTION_USER_PRESENT , which will take care of your ALARM reset and update task.
Thanks.