开发者

How to keep a task alive after phone sleeps?

开发者 https://www.devze.com 2023-04-08 14:57 出处:网络
my application needs to send a message to my server every 30 seconds or so. I understand I need to use AlarmManager using RT开发者_Go百科C_WAKEUP or ELAPSED_REALTIME_WAKEUP.

my application needs to send a message to my server every 30 seconds or so.

I understand I need to use AlarmManager using RT开发者_Go百科C_WAKEUP or ELAPSED_REALTIME_WAKEUP.

now I don't understand two things:

1) If the AlarmManager wakes up the device, why do I need to aquire a WakeLock?

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号