如何使用monkeyrunner重启Android模拟器?

时间:2011-02-11 08:21:12

标签: android android-emulator monkeyrunner

这个脚本有什么问题?

# 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')

我也尝试过更改bootloadType。我尝试使用的最后一行,device.reboot('bootloader')和device.reboot('recovery'),但它也没有用。

1 个答案:

答案 0 :(得分:0)

Android dev here发布以下内容:

  

“rebo​​ot”实际上是一个硬件   重启,而“停止”/“开始”是一个   软件重启。

理想情况下,您应该能够使用:

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

...但是针对模拟器的启动/停止提出了here错误> = 2.2。

就个人而言,我使用一个讨厌的小shell脚本来杀死所有模拟器实例,然后再次启动模拟器:

#!/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

此脚本可以通过传入特定模拟器的序列号来终止(可以使用“adb get-serialno”获取序列号)

我想知道其他人的想法/他们如何自动重启模拟器。