Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reboot emulator to test ACTION_BOOT_COMPLETED?

People also ask

How do I manually start an emulator?

Build and package your app into an APK as described in Build and Run Your App. Start the emulator from the command line as described in the previous section, using any startup options necessary. Install your app using adb. Run and test your app on the emulator.


You can use the following command from adb:

adb shell am activity/service/broadcast -a ACTION -c CATEGORY -n NAME

for example:

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n package_name/class_name

Note that class name and package names need to be as defined in the Manifest.

This will generate the Intent you want , directed only to the component you want (otherwise you system will go crazy with BOOT_COMPLETED sent...)


Or another way (also from the command line):

adb shell stop
adb shell start

First, make sure that USB Debugging is enabled from within the emulator:

click:

  • the Home icon
  • Menu icon
  • 'Settings'
  • 'Applications'
  • 'Development'
  • make sure that the box next to 'USB debugging' contains a check mark

from a command-line:

adb -e reboot

EDIT:

This definitely doesn't work... very strange. I tested it and could not make the emulator reboot. It just hangs.


To emulate a broadcast action, you can connect via adb to the emulator/device and open a shell:

adb shell

Then, you can broadcast the action you want to test:

am broadcast -a android.intent.action.BOOT_COMPLETED

Please note that, in the latest Android versions, broadcasting the *android.intent.action.BOOT_COMPLETED* action will actually reboot your emulator/device.