AlarmManager VS服务的数据库和FTP连接。哪些以及如何使用? [英] AlarmManager vs Service for db and FTP connection. Which and how to use?
问题描述
我的问题很简单,但可能附带一个复杂的答案。
我在做一个应用程序,(在网站上通过一个PHP脚本)上的在线MySQL数据库检查新的更新。有时,这种更新会告诉它的应用程序下载构成一个FTP服务器。
应用程序应启动时自动打开并检查更新每隔15分钟。
我读过的网页我应该或者使用服务或AlarmManager,但我不知道哪一个更好。
另外,我读了很多的说AlarmManager将唤醒该设备的网页,但我不明白这到底是什么意思,为什么它在一个服务不同。这是否意味着,如果手机处于关机状态,将打开它,或者它会变成在屏幕上?
我只需要手机做任务在后台时,它的上,我并不需要它来打开屏幕或功率器件。
我读过的网页我应该或者使用服务或AlarmManager,但我不知道哪一个更好。
这不是一个或。这是一个和。您将需要使用 AlarmManager
来触发要由服务
。
我已经阅读了大量的网页说,AlarmManager将唤醒的设备,但我不明白这到底是什么意思
这是 AlarmManager
_WAKEUP
事件类型(例如, ELAPSED_REALTIME_WAKEUP
)将器件唤醒退出睡眠模式。也就是说,在东西一起像 WakefulBroadcastReceiver
和 IntentService
,可以安排你做你的工作周期,即使设备通常会睡着了(屏幕和CPU处于睡眠状态)。
我只需要手机做任务在后台时,它的上,我并不需要它来打开屏幕或功率器件。
然后你可以用 AlarmManager
与非 - _WAKEUP
报警类型(例如, ELAPSED_REALTIME
)。我仍然会建议使用 WakefulBroadcastReceiver
和 IntentService
,以确保设备不会在中间入睡你在做什么,因为这可能会导致你的工作问题。
My question is rather simple but might come with a complex answer.
I'm making an App that checks on an online mysql db (via a php script on the website) for new updates. Sometimes this updates will tell the App it has to download form a FTP server.
The App should start on boot and check for updates every 15 minutes.
I've read in the web I should either use a service or a AlarmManager but I don't know which one is better.
Also, I've read a lot of pages that say that AlarmManager will "Wake Up" the device but I've failed to understand what this really means and why it's different in a service. Does this means that if the Phone is turned off it will turn it on or that it will turn on the screen?
I only need the phone to do the task in the background when it's on, I don't need it to turn the screen on or power up the device.
I've read in the web I should either use a service or a AlarmManager but I don't know which one is better.
It's not an "or". It's an "and". You will need to use AlarmManager
to trigger the work to be done by a Service
.
I've read a lot of pages that say that AlarmManager will "Wake Up" the device but I've failed to understand what this really means
An AlarmManager
_WAKEUP
event type (e.g., ELAPSED_REALTIME_WAKEUP
) will wake up the device out of sleep mode. That, in conjunction with something like WakefulBroadcastReceiver
and an IntentService
, can arrange for you to do your work periodically even though the device would ordinarily be asleep (screen and CPU in a sleep state).
I only need the phone to do the task in the background when it's on, I don't need it to turn the screen on or power up the device.
Then you can use AlarmManager
with a non-_WAKEUP
alarm type (e.g., ELAPSED_REALTIME
). I would still recommend using WakefulBroadcastReceiver
and an IntentService
, to make sure that the device does not fall asleep in the middle of what you are doing, as that may cause problems for your work.
这篇关于AlarmManager VS服务的数据库和FTP连接。哪些以及如何使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!