How can I reboot Android Emulator using monkeyrunner?

1.5k views Asked by At

What is wrong with this script?

# Imports the monkeyrunner modules used by this program 
 from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
# Connects to the current device, returning a MonkeyDevice object 
device = MonkeyRunner.waitForConnection() 
#Reboot 
device.reboot('None')

I also tried changing the bootloadType. Insted of the last line I tried with, device.reboot('bootloader') and device.reboot('recovery'), but it didn't work either.

1

There are 1 answers

0
dstricks On

Post by an Android dev here says the following:

"reboot" is effectively a hardware reboot, while "stop"/"start" is a software restart.

For emulator ideally you should be able to use:

device.shell('stop');
device.shell('start');

... but there is a bug raised here against start/stop for emulators >= 2.2.

Personally, I use a nasty little shell script to kill off all emulator instances and then start the emulator again:

#!/bin/bash

pgrep -x "emulator" > /dev/null
until [  $? -eq 1 ]; do
  kill `pgrep -x "emulator" | cut -c 1-6`
  sleep 2
  pgrep -x "emulator"
done

# start emulator normally...
exit 0

This script can be refined by passing in a serial number of a particular emulator to kill off (can get the serial number using "adb get-serialno")

I'd be intereted in seeing what others think/ways they are automating restart of emulator.