从服务器的Android轮询周期 [英] Android Polling from a Server periodically
问题描述
我想从服务器获取一些数据每隔x分钟。如果该信息中包含的某些信息,我想创建一个通知。我想这个投票站发生,即使该应用程序在后台,或手机睡着了。我在android的有关投票的几个问题。
I want to pull some data from a server every x minutes. IF the info contains certain information I would like to create a notification. I want this polling to happen even when the app is in the background, or the phone is asleep. I have a few questions about polling in android.
-
什么是去这样做的最好方法是什么?我应该使用
IntentService,一个AlarmManager,其他什么东西?
What is the best way to go about doing it? Should I use an
IntentService, an AlarmManager, something else?
我应该多久是轮询的数据?我想保持它 相对频繁,说每隔10分钟下。
How often should I be polling the data? I would like to keep it relatively often, say under every 10 minutes.
推荐答案
我赞成一个 AlarmManager
,我尽量不连续运行正在运行的服务,除非我真的需要,但它真的取决于你将如何使用它。
I would favour an AlarmManager
as I try not to run continuously running services unless I really need to but it does really depend on how you will be using it.
如果是我的话我会(基于有限的描述): -
If it were me I would (based on the limited description) :-
- 设置了一个
AlarmManager
火在说10分钟。 - 在响应报警,启动一个服务,调查的数据。
- 在投票后,它应该为自己设定了一个新的报警再过10分钟后再次触发。
- 在该服务自动关闭。
- Set up an
AlarmManager
to fire in say 10 minutes. - In response to the alarm, start a service that polls the data.
- After polling it should set itself up with a new Alarm to fire again in another 10 minutes.
- The service shuts itself down.
这篇关于从服务器的Android轮询周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!