How to keep a task alive after phone sleeps?

青春壹個敷衍的年華 提交于 2019-12-11 07:43:18

问题


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

I understand I need to use AlarmManager using RTC_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?


回答1:


Here you can find a promising piece of code. Examples at developers are not always correct.



来源:https://stackoverflow.com/questions/7552471/how-to-keep-a-task-alive-after-phone-sleeps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!