Creating and registering a standalone receiver
Next, open AndroidManifest.xml and hook up StartupReceiver as a standalone receiver:
Listing 29.2 Adding your receiver to the manifest (AndroidManifest.xml)
<manifest ...>
<application
...>
<activity
android:name=".PhotoGalleryActivity"
android:label="@string/app_name">
...
Registering a standalone receiver to respond to an implicit intent works just like registering an activity
to do the same. You use the receiver tag with appropriate intent-filters. StartupReceiver will
be listening for the BOOT_COMPLETED action. This action also requires a permission, so you include an
appropriate uses-permission tag as well.
With your broadcast receiver declared in your manifest, it will wake up any time a matching broadcast
intent is sent – even if your app is not currently running. Upon waking up, the ephemeral broadcast
receiver’s onReceive(Context, Intent) method will be run, and then it will die, as shown in
Figure 29.2.
Figure 29.2 Receiving BOOT_COMPLETED