BroadcastReceiver类onReceive方法求解.
因为我要再BroadcastReceiver里面启动Activity,所以就上网搜索了下相关的信息.
有很多人讨论的时候都说最好不要这样,还给出了API帮助文档里面的说明.
目前我使用是没问题的,但是如果官方说不要这样,那肯定是有问题的,于是我拿起帮助文档通过和google翻译一起努力,查看了下面的这段说明:
This method is called when the BroadcastReceiver is receiving an Intent broadcast. During this time you can use the other methods on BroadcastReceiver to view/modify the current result values. The function is normally called within the main thread of its process, so 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). You cannot launch a popup dialog in your implementation of onReceive().
我的理解是这样的:
onReceive()是当BroadcastReceiver收到Intent广播后调用的回调函数.
在此期间,你可以使用BroadcastReceiver的其它方法查看/修改Intent的数据.
这个函数运行在其进程的主线程,所以你不应该让它执行耗时的操作.
(如果一个进程的主线程被阻塞10秒,那么系统会提示用户kill掉此进程)(我试了新开线程也只是允许20秒阻塞)
不要在onReceiver()里面启动一个弹出对话框.
疑问就是,如果onReceive()的操作不造成阻塞,那么就没问题了不是吗?
但是最后为什么还要说:不要在onReceiver()里面启动一个弹出对话框.