BroadcastReceivers的重要特性

来源:互联网 发布:wifi软件哪个好用 知乎 编辑:程序博客网 时间:2024/06/03 19:13

1. A broadcast receiver, like other components of an An droid process, 
runs on the main thread.  
2. Holding up the code in a broadcast receiver will hold up the main 
thread and will result in ANR.  
3.The time limit on a broadcast receiver is ten seconds compared to five 
seconds for an activity. It is a touch of a reprieve, but the limit is still 
there. 
4. The process hosting the broadcast receiver will start and terminate 
along with the broadcast receiver execution. Hence the process will 
not stick around after  the broadcast receiver’s onReceive()  method 
returns. Of course, this is assumi ng that the process contains only the 
broadcast receiver. If the process contains other components, such as 
activities or services, that are alr eady running, then the lifetime of the 
process takes these component life cycles into account as well. 
5. Unlike a service process, a broadcast receiver process will not get restarted.  
If a broadcast receiver were to start  a separate thread  and return to 
the main thread, Android will assume that the work is complete and 
will shut down the process even if there are threads running, bringing 
those threads to abrupt stop.  
6. Android acquires a partial wake lock when invoking a broadcast 
service and releases it when it re turns from the service in the main 
thread. A wake lock is a mechanism  and an API class available in the 
SDK to keep the device from going to sleep or wake it up if it is 
already asleep.
原创粉丝点击