从网站检索数据
我有一个应用程序,应该每 x 分钟从网站检索数据。像推送服务这样的东西是不可能的。检索数据后,通知应出现在信息栏或您所说的任何地方。我一直在阅读,起初我认为我应该做一个包含本地服务的新线程。比我发现 AlarmManager 并认为“woa”应该更好,因为 AlarmManager 还使用某种唤醒以便在睡眠时运行给定的 Intent。所以我的最终决定是使用一个警报来启动一项服务,该服务每 x 分钟进行一次数据收集和通知。
我的问题是:
这真的是最好的方法吗?
AlarmManager 是否会自动在新线程中启动服务?如果不是我该怎么做。 (只需创建一个新线程来初始化警报?)
I have an application which is supposed to retrieve data from a Website every x minutes. Something like a push service is not possible. After retrieving the data a notification should appeare at the info bar or what ever you call it. I was reading and reading and at first I thought I should do a new thread which contains a localservice. Than I found out about the AlarmManager and thought "woa" that should be even better since the AlarmManager is also using some kind of wake-up in order to run a given Intent while sleeping. So my final decision is to use an alarm which starts a service which is doing the data collection and notification every x minutes.
The questions I have are:
Is this really the best way to do it.
Does AlarmManager automatically start the service in a new thread? If not how do I do this. (Just create a new thread in which I initialize the alarm?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您对如何做感到困惑。你需要把所有这些东西放在一起。
AlarmManager 触发启动服务的意图(通过 BroadcastReceiver)。服务创建新线程,您可以在其中获取数据。
You are confused about how to do it. You need all that things together.
AlarmManager fires the intent which starts the service(via BroadcastReceiver). Service creates new thread, inside which you can fetch data.