WEB开发网
开发学院手机开发Android 开发 Android:BroadcastReceiver 阅读

Android:BroadcastReceiver

 2010-10-19 20:16:47 来源:WEB开发网   
核心提示:time to avoid overloading the system with new processes. In this situation, however, the non-ordered semantics hold: these receivers still cannot return results
time to avoid overloading the system with new processes. In this situation, however, the non-ordered semantics hold: these receivers still cannot return results or abort their broadcast.

Note that, although the Intent class is used for sending and receiving these broadcasts, the Intent broadcast mechanism here is completely separate from Intents that are used to start Activities with Context.startActivity(). There is no way for a BroadcastReceiver to see or capture Intents used with startActivity(); likewise, when you broadcast an Intent, you will never find or start an Activity. These two operations are semantically very different: starting an Activity with an Intent is a foreground operation that modifies what the user is currently interacting with; broadcasting an Intent is a background operation that the user is not normally aware of.

注意:通过Context.startActivity启动Intent和使用BroadcastReceiver广播Intent在运行方式中是不同的,前者是处于前台的,而后者处于后台的。

The BroadcastReceiver class (when launched as a component through a manifest's tag) is an important part of an application's overall lifecycle.

Topics covered here:

Receiver Lifecycle

Permissions

Process Lifecycle

Receiver Lifecycle

A BroadcastReceiver object is only valid for the duration of the call to onReceive(Context, Intent). Once your code returns from this function, the system considers the object to be finished and no longer active.

This has important repercussions不良后果 to what you can do in an onReceive(Context, Intent) implementation: anything that requires asynchronous operation is not available, because you will need to return from the function to handle the asynchronous operation, but at that point the BroadcastReceiver is no longer active and thus the system is free to kill its process before the asynchronous operation completes.

上一页  1 2 3 4 5 6  下一页

Tags:Android BroadcastReceiver

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接