diff --git a/core/java/android/app/AlarmManager.java b/core/java/android/app/AlarmManager.java index b4c0e314cfb62..53c79352d3f4a 100644 --- a/core/java/android/app/AlarmManager.java +++ b/core/java/android/app/AlarmManager.java @@ -29,6 +29,17 @@ import android.os.ServiceManager; * if it is not already running. Registered alarms are retained while the * device is asleep (and can optionally wake the device up if they go off * during that time), but will be cleared if it is turned off and rebooted. + * + *
The Alarm Manager holds a CPU wake lock as long as the alarm receiver's + * onReceive() method is executing. This guarantees that the phone will not sleep + * until you have finished handling the broadcast. Once onReceive() returns, the + * Alarm Manager releases this wake lock. This means that the phone will in some + * cases sleep as soon as your onReceive() method completes. If your alarm receiver + * called {@link android.content.Context#startService Context.startService()}, it + * is possible that the phone will sleep before the requested service is launched. + * To prevent this, your BroadcastReceiver and Service will need to implement a + * separate wake lock policy to ensure that the phone continues running until the + * service becomes available. * *
Note: The Alarm Manager is intended for cases where you want to have
* your application code run at a specific time, even if your application is
diff --git a/core/java/android/content/BroadcastReceiver.java b/core/java/android/content/BroadcastReceiver.java
index a41627aa3ab4d..b391c57df5ee6 100644
--- a/core/java/android/content/BroadcastReceiver.java
+++ b/core/java/android/content/BroadcastReceiver.java
@@ -44,14 +44,14 @@ import android.util.Log;
*
*
Note that, although the Intent class is used for sending and receiving * these broadcasts, the Intent broadcast mechanism here is completely separate @@ -156,7 +156,7 @@ import android.util.Log; * more important processes. * *
This means that for longer-running operations you will often use - * an {@link android.app.Service} in conjunction with a BroadcastReceiver to keep + * a {@link android.app.Service} in conjunction with a BroadcastReceiver to keep * the containing process active for the entire time of your operation. */ public abstract class BroadcastReceiver { @@ -167,7 +167,7 @@ public abstract class BroadcastReceiver { * 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 from the main thread of its process, so you should + * 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 @@ -183,6 +183,14 @@ public abstract class BroadcastReceiver { * to interact with a service that is already running, you can use * {@link #peekService}. * + *
The Intent filters used in {@link android.content.Context#registerReceiver} + * and in application manifests are not guaranteed to be exclusive. They + * are hints to the operating system about how to find suitable recipients. It is + * possible for senders to force delivery to specific recipients, bypassing filter + * resolution. For this reason, {@link #onReceive(Context, Intent) onReceive()} + * implementations should respond only to known actions, ignoring any unexpected + * Intents that they may receive. + * * @param context The Context in which the receiver is running. * @param intent The Intent being received. */ diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index abcc1eaf5a2bd..3d5ed3a87ffcc 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -738,7 +738,7 @@ public abstract class Context { public abstract void removeStickyBroadcast(Intent intent); /** - * Register an BroadcastReceiver to be run in the main activity thread. The + * Register a BroadcastReceiver to be run in the main activity thread. The * receiver will be called with any broadcast Intent that * matches filter, in the main application thread. * @@ -762,11 +762,12 @@ public abstract class Context { * *
See {@link BroadcastReceiver} for more information on Intent broadcasts. * - *
Note: this method can not be called from an - * {@link BroadcastReceiver} component. It is okay, however, to use - * this method from another BroadcastReceiver that has itself been registered with - * {@link #registerReceiver}, since the lifetime of such an BroadcastReceiver - * is tied to another object (the one that registered it).
+ *Note: this method cannot be called from a + * {@link BroadcastReceiver} component; that is, from a BroadcastReceiver + * that is declared in an application's manifest. It is okay, however, to call + * this method from another BroadcastReceiver that has itself been registered + * at run time with {@link #registerReceiver}, since the lifetime of such a + * registered BroadcastReceiver is tied to the object that registered it.
* * @param receiver The BroadcastReceiver to handle the broadcast. * @param filter Selects the Intent broadcasts to be received. diff --git a/docs/html/guide/topics/manifest/receiver-element.jd b/docs/html/guide/topics/manifest/receiver-element.jd index 777d016b5da8d..8df6273bbf990 100644 --- a/docs/html/guide/topics/manifest/receiver-element.jd +++ b/docs/html/guide/topics/manifest/receiver-element.jd @@ -17,7 +17,7 @@ page.title=<receiver><application><intent-filer>
+<intent-filter>
<meta-data><
enabled attribute that applies to all
application components, including broadcast receivers. The
<application> and
-{@code <receiver>} attributes must both be "{@code true}" for
-the broadcast receiver to be enabled. If either is "{@code false}", it is
-disabled; it cannot be instantiated.
-
+{@code <receiver>} elements must both set {@code android:enabled} equal to
+"{@code true}" for the broadcast receiver to be enabled. If either is "{@code false}",
+the receiver is disabled and cannot be instantiated.
+
+
+
+The default value depends on whether the broadcast receiver contains intent filters.
+If any intent filters are specified, the default value is "{@code true}". If no
+filters are specified, the default value is "{@code false}".
+
{@code android:exported}
Whether or not the broadcast receiver can receive messages from sources
@@ -117,9 +123,12 @@ it can also be set as a raw string.
{@link android.content.BroadcastReceiver}. This should be a fully qualified
class name (such as, "{@code com.example.project.ReportReceiver}"). However,
as a shorthand, if the first character of the name is a period (for example,
-"{@code . ReportReceiver}"), it is appended to the package name specified in
+"{@code .ReportReceiver}"), it is appended to the package name specified in
the <manifest> element.
+The {@link android.content.BroadcastReceiver} subclass can be a static inner
+class, although it cannot be an ordinary (non-static) inner class.
+
There is no default. The name must be specified.