问题描述
我的应用程序需要将消息发送到我的服务器每隔30秒左右。
my application needs to send a message to my server every 30 seconds or so.
我明白我需要使用RTC_WAKEUP或ELAPSED_REALTIME_WAKEUP AlarmManager使用。
I understand I need to use AlarmManager using RTC_WAKEUP or ELAPSED_REALTIME_WAKEUP.
现在我不明白两件事情:
now I don't understand two things:
1)如果AlarmManager唤醒器件,为什么我需要一个AQUIRE激活锁定?
1) If the AlarmManager wakes up the device, why do I need to aquire a WakeLock?
2)我看到了使用AlarmManager与激活锁定一个例子。在这个例子中,它的设置报警到广播发送到广播接收器,其然后获取一个静态唤醒锁,然后启动它运行一个任务的IntentService
2) I saw an example for using AlarmManager with WakeLock. In this example, its setting the alarm to send a broadcast to a broadcast receiver which then acquires a static wake lock and then start an IntentService which runs a task.
现在,我的问题是,在我的情况,我需要完全遵循这个例子吗?为什么不将闹钟设置为启动服务呢?
now, my question is, in my case, I need to follow this example entirely? why don't set the alarm to start a service instead?
推荐答案
你可以找到一个前途一片code的。在开发商的例子并不总是正确的。
Here you can find a promising piece of code. Examples at developers are not always correct.
这篇关于如何保持一个任务活着的手机睡觉之后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!