BroadcastReceiver wake lock needed if only AsyncTask is executed?

。_饼干妹妹 提交于 2019-12-06 19:19:27

I suggest you to read the docs about the receiver lifecycle. What you are trying to do is not good practice, If the onReceive() method returns the process can be killed. Hence your task can't complete the work. Because of this you should start a Service/IntentService to run the task and to keep the process alive.

The OnReceive method reference from the BroadcastReceiver doc says :

..you should never perform long-running operations in it (there is a timeout of 10 seconds that the system allows before considering the receiver to be blocked and a candidate to be killed)

So you'd better replace your AsyncTask with a service and then call this service from the OnReceive method. Your service will keep running even if the broadcastReceiver get killed.

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