我正在经历猴子的有趣行为。当应用程序显示带有两个按钮的 AlertDialog 时,我的 onClick 处理程序有时会调用两次。当我手动按下按钮时不会发生这种情况,只有在使用猴子时才会发生。
这是我的活动代码:
@Override
public void onResume() {
super.onResume();
Log.d(TAG, "onResume");
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setPositiveButton("yes", this)
.setNegativeButton("no", this);
AlertDialog alert = builder.create();
alert.show();
}
@Override
public void onClick(DialogInterface pDialog, int pWhich) {
Log.d(TAG, "onClick " + pWhich);
pDialog.dismiss();
}
这就是我所说的猴子:
adb shell monkey -p com.mycompany.helloapp -v 500
这里是 logcat 输出(不相关的行被跳过):
09-26 12:27:04.867 D/ClickTest(27989): onResume
09-26 12:27:07.557 D/ClickTest(27989): onClick -1
09-26 12:27:07.557 D/ClickTest(27989): onClick -1
我做错了什么,或者这是在高事件负载下重现的 android UI 事件处理程序中的某种错误?
-列夫