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

Android:BroadcastReceiver

 2010-10-19 20:16:47 来源:WEB开发网   
核心提示:process was only hosting the BroadcastReceiver (a common case for applications that the user has never or not recently interacted with), then upon returning fro
process was only hosting the BroadcastReceiver (a common case for applications that the user has never or not recently interacted with), then upon returning from onReceive() the system will consider its process to be empty and aggressively kill it so that resources are available for other more important processes.

This means that for longer-running operations you will often use a Service in conjunction with a BroadcastReceiver to keep the containing process active for the entire time of your operation.

需要特别注意的是:如果hosting process中只有Broadcast Receiver的话,一旦Broadcast Receiver的onReceive()函数执行完后,就会被系统认为是空进程,而被杀掉。所以一般要使Broadcast Receiver长期在操作过程中有效的话,就和Service一起绑定使用。

下面是一些常用的成员函数:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~·

public final String getResultData ()

Since: API Level 1

Retrieve the current result data, as set by the previous receiver. Often this is null.

Returns

String The current result data; may be null.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~·

public abstract void onReceive (Context context, Intent intent)

Since: API Level 1

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().

If this BroadcastReceiver was launched through a tag, then the object is no longer alive after returning from this function. This means you

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

Tags:Android BroadcastReceiver

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