从网站检索数据

发布于 2024-11-15 23:09:09 字数 350 浏览 3 评论 0原文

我有一个应用程序,应该每 x 分钟从网站检索数据。像推送服务这样的东西是不可能的。检索数据后,通知应出现在信息栏或您所说的任何地方。我一直在阅读,起初我认为我应该做一个包含本地服务的新线程。比我发现 AlarmManager 并认为“woa”应该更好,因为 AlarmManager 还使用某种唤醒以便在睡眠时运行给定的 Intent。所以我的最终决定是使用一个警报来启动一项服务,该服务每 x 分钟进行一次数据收集和通知。

我的问题是:

  1. 这真的是最好的方法吗?

  2. 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:

  1. Is this really the best way to do it.

  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

看海 2024-11-22 23:09:09

您对如何做感到困惑。你需要把所有这些东西放在一起。
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.

西瓜 2024-11-22 23:09:09
  1. 在这种情况下,AlarmManager 似乎是执行此操作的正确方法。
  2. 从 AlarmManager 您需要创建服务器/线程来执行所需的任务。
  1. At this situation AlarmManager seems to be a right way to do this.
  2. From AlarmManager you need to create the server/thread to perform desire task.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文