Android:BroadcastReceiver
2010-10-19 20:16:47 来源:WEB开发网In particular, you may not show a dialog or bind to a service from within a BroadcastReceiver. For the former, you should instead use the NotificationManager API. For the latter, you can use Context.startService() to send a command to the service.
BroadcastReceiver的生命期只处于调用onReceive期间,所以在onReceive函数执行过程中,不能调用异步操作。也不能显示对话框或和某个服务进行绑定。
Permissions
Access permissions can be enforced by either the sender or receiver of an Intent.
To enforce a permission when sending, you supply a non-null permission argument to sendBroadcast(Intent, String) or sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler, int, String, Bundle). Only receivers who have been granted this permission (by requesting it with the tag in their AndroidManifest.xml) will be able to receive the broadcast.
To enforce a permission when receiving, you supply a non-null permission when registering your receiver -- either when calling registerReceiver(BroadcastReceiver, IntentFilter, String, android.os.Handler) or in the static tag in your AndroidManifest.xml. Only broadcasters who have been granted this permission (by requesting it with the tag in their AndroidManifest.xml) will be able to send an Intent to the receiver.
See the Security and Permissions document for more information on permissions and security in general.
Process Lifecycle
A process that is currently executing a BroadcastReceiver (that is, currently running the code in its onReceive(Context, Intent) method) is considered to be a foreground process and will be kept running by the system except under cases of extreme memory pressure.
Once you return from onReceive(), the BroadcastReceiver is no longer active, and its hosting process is only as important as any other application components that are running in it. This is especially important because if that
Tags:Android BroadcastReceiver
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接