Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1

Chapter 29  Broadcast Intents


Time to verify that StartupReceiver’s onReceive(...) is executed when the device boots up. First, run
PhotoGallery to install the most recent version on your device.


Next, shut down your device. If you are using a physical device, power it all the way off. If you are
using an emulator, the easiest way to shut it down is to quit out of the emulator by closing the emulator
window.


Turn the device back on. If you are using a physical device, use the power button. If you are using an
emulator, either rerun your application or start the device using the AVD Manager. Make sure you are
using the same emulator image you just shut down.


Now, open the Android Device Monitor by selecting Tools → Android → Android Device Monitor.


Click on your device in Android Device Monitor’s Devices tab. (If you do not see the device listed, try
unplugging and replugging your USB device or restarting the emulator.)


Search the Logcat results within the Android Device Monitor window for your log statement
(Figure 29.3).


Figure 29.3  Searching Logcat output


You should see a Logcat statement showing that your receiver ran. However, if you check your device
in the Devices tab, you will probably not see a process for PhotoGallery. Your process came to life just
long enough to run your broadcast receiver, and then it died again.


(Testing that the receiver executed can be unreliable when you are using Logcat output, especially if
you are using an emulator. If you do not see the log statement the first time through the instructions
above, try a few more times. Worst case, continue through the rest of the exercise. Once you get to the
part where you hook up notifications, you will have a more reliable way to check whether the receiver
is working.)

Free download pdf