Robotium.clickOnMenuItem() 的问题
当我调用 Robotium 时:
solo.clickOnMenuItem("Sync");
有时我会得到著名的错误跟踪:
09-19 22:27:23.647:错误/WindowManager(20662):android.view.WindowLeaked:活动test.com.activities.ListActivity已泄漏窗口com.android.internal.policy.impl.PhoneWindow$DecorView@ 461d4660 最初添加在这里 09-19 22:27:23.647:错误/WindowManager(20662):在android.view.ViewRoot。(ViewRoot.java:253) 09-19 22:27:23.647:错误/WindowManager(20662):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148) 09-19 22:27:23.647:错误/WindowManager(20662):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) 09-19 22:27:23.647:错误/WindowManager(20662):在 android.view.Window$LocalWindowManager.addView(Window.java:424) 09-19 22:27:23.647:错误/WindowManager(20662):在android.app.Dialog.show(Dialog.java:241) 09-19 22:27:23.647:错误/WindowManager(20662):在 test.com.activities.ListActivity$Sincronizacao.onPreExecute(ListActivity.java:272) 09-19 22:27:23.647:错误/WindowManager(20662):在android.os.AsyncTask.execute(AsyncTask.java:391) 09-19 22:27:23.647:错误/WindowManager(20662):在test.com.activities.ListActivity.onOptionsItemSelected(ListActivity.java:224) 09-19 22:27:23.647:错误/WindowManager(20662):在android.app.Activity.onOptionsItemSelected(Activity.java:2313) 09-19 22:27:23.647:错误/WindowManager(20662):在android.app.Activity.onMenuItemSelected(Activity.java:2201) 09-19 22:27:23.647:错误/WindowManager(20662):在com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:740) 09-19 22:27:23.647:错误/WindowManager(20662):在com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143) 09-19 22:27:23.647:错误/WindowManager(20662):在com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855) 09-19 22:27:23.647:错误/WindowManager(20662):在com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:538) 09-19 22:27:23.647:错误/WindowManager(20662):在com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:142) 09-19 22:27:23.647:错误/WindowManager(20662):在 android.view.View$PerformClick.run(View.java:8818) 09-19 22:27:23.647:错误/WindowManager(20662):在android.os.Handler.handleCallback(Handler.java:587) 09-19 22:27:23.647:错误/WindowManager(20662):在android.os.Handler.dispatchMessage(Handler.java:92) 09-19 22:27:23.647:错误/WindowManager(20662):在android.os.Looper.loop(Looper.java:143) 09-19 22:27:23.647:错误/WindowManager(20662):在android.app.ActivityThread.main(ActivityThread.java:4701) 09-19 22:27:23.647:错误/WindowManager(20662):在java.lang.reflect.Method.invokeNative(本机方法) 09-19 22:27:23.647:错误/WindowManager(20662):在java.lang.reflect.Method.invoke(Method.java:521) 09-19 22:27:23.647:错误/WindowManager(20662):在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 09-19 22:27:23.647:错误/WindowManager(20662):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 09-19 22:27:23.647:错误/WindowManager(20662):在dalvik.system.NativeStart.main(本机方法) 09-19 22:27:24.209:错误/AndroidRuntime(20662):致命异常:主要 09-19 22:27:24.209:错误/AndroidRuntime(20662):java.lang.IllegalArgumentException:视图未附加到窗口管理器 09-19 22:27:24.209:错误/AndroidRuntime(20662):在android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:355) 09-19 22:27:24.209:错误/AndroidRuntime(20662):在android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:200) 09-19 22:27:24.209: 错误/AndroidRuntime(20662): 在 android.view.Window$LocalWindowManager.removeView(Window.java:432) 09-19 22:27:24.209:错误/AndroidRuntime(20662):在android.app.Dialog.dismissDialog(Dialog.java:278) 09-19 22:27:24.209: 错误/AndroidRuntime(20662): 在 android.app.Dialog.access$000(Dialog.java:71) 09-19 22:27:24.209:错误/AndroidRuntime(20662):在android.app.Dialog$1.run(Dialog.java:111) 09-19 22:27:24.209:错误/AndroidRuntime(20662):在android.app.Dialog.dismiss(Dialog.java:268) 09-19 22:27:24.209:错误/AndroidRuntime(20662):在android.app.Dialog.cancel(Dialog.java:951) 09-19 22:27:24.209: 错误/AndroidRuntime(20662): 在 test.com.activities.ListActivity$Sincronizacao.onPostExecute(ListActivity.java:331) 09-19 22:27:24.209:错误/AndroidRuntime(20662):在android.os.AsyncTask.finish(AsyncTask.java:417) 09-19 22:27:24.209:错误/AndroidRuntime(20662):在android.os.AsyncTask.access$300(AsyncTask.java:127) 09-19 22:27:24.209:错误/AndroidRuntime(20662):在 android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429) 09-19 22:27:24.209:错误/AndroidRuntime(20662):在android.os.Handler.dispatchMessage(Handler.java:99) 09-19 22:27:24.209:错误/AndroidRuntime(20662):在android.os.Looper.loop(Looper.java:143) 09-19 22:27:24.209:错误/AndroidRuntime(20662):在android.app.ActivityThread.main(ActivityThread.java:4701) 09-19 22:27:24.209:错误/AndroidRuntime(20662):在java.lang.reflect.Method.invokeNative(本机方法) 09-19 22:27:24.209:错误/AndroidRuntime(20662):在java.lang.reflect.Method.invoke(Method.java:521) 09-19 22:27:24.209:错误/AndroidRuntime(20662):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:860) 09-19 22:27:24.209:错误/AndroidRuntime(20662):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 09-19 22:27:24.209:错误/AndroidRuntime(20662):在dalvik.system.NativeStart.main(本机方法)
但是如果我像这样本地调用(菜单项是第三个):
mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);
mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_RIGHT);
mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_RIGHT);
mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_ENTER);
我不无论我运行测试多少次,都会出现任何错误。为什么我会出现这种行为?
When I make this call to Robotium:
solo.clickOnMenuItem("Sync");
sometimes I get the famous error trace:
09-19 22:27:23.647: ERROR/WindowManager(20662): android.view.WindowLeaked: Activity test.com.activities.ListActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@461d4660 that was originally added here
09-19 22:27:23.647: ERROR/WindowManager(20662): at android.view.ViewRoot.(ViewRoot.java:253)
09-19 22:27:23.647: ERROR/WindowManager(20662): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
09-19 22:27:23.647: ERROR/WindowManager(20662): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
09-19 22:27:23.647: ERROR/WindowManager(20662): at android.view.Window$LocalWindowManager.addView(Window.java:424)
09-19 22:27:23.647: ERROR/WindowManager(20662): at android.app.Dialog.show(Dialog.java:241)
09-19 22:27:23.647: ERROR/WindowManager(20662): at test.com.activities.ListActivity$Sincronizacao.onPreExecute(ListActivity.java:272)
09-19 22:27:23.647: ERROR/WindowManager(20662): at android.os.AsyncTask.execute(AsyncTask.java:391)
09-19 22:27:23.647: ERROR/WindowManager(20662): at test.com.activities.ListActivity.onOptionsItemSelected(ListActivity.java:224)
09-19 22:27:23.647: ERROR/WindowManager(20662): at android.app.Activity.onOptionsItemSelected(Activity.java:2313)
09-19 22:27:23.647: ERROR/WindowManager(20662): at android.app.Activity.onMenuItemSelected(Activity.java:2201)
09-19 22:27:23.647: ERROR/WindowManager(20662): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:740)
09-19 22:27:23.647: ERROR/WindowManager(20662): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
09-19 22:27:23.647: ERROR/WindowManager(20662): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
09-19 22:27:23.647: ERROR/WindowManager(20662): at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:538)
09-19 22:27:23.647: ERROR/WindowManager(20662): at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:142)
09-19 22:27:23.647: ERROR/WindowManager(20662): at android.view.View$PerformClick.run(View.java:8818)
09-19 22:27:23.647: ERROR/WindowManager(20662): at android.os.Handler.handleCallback(Handler.java:587)
09-19 22:27:23.647: ERROR/WindowManager(20662): at android.os.Handler.dispatchMessage(Handler.java:92)
09-19 22:27:23.647: ERROR/WindowManager(20662): at android.os.Looper.loop(Looper.java:143)
09-19 22:27:23.647: ERROR/WindowManager(20662): at android.app.ActivityThread.main(ActivityThread.java:4701)
09-19 22:27:23.647: ERROR/WindowManager(20662): at java.lang.reflect.Method.invokeNative(Native Method)
09-19 22:27:23.647: ERROR/WindowManager(20662): at java.lang.reflect.Method.invoke(Method.java:521)
09-19 22:27:23.647: ERROR/WindowManager(20662): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
09-19 22:27:23.647: ERROR/WindowManager(20662): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
09-19 22:27:23.647: ERROR/WindowManager(20662): at dalvik.system.NativeStart.main(Native Method)
09-19 22:27:24.209: ERROR/AndroidRuntime(20662): FATAL EXCEPTION: main
09-19 22:27:24.209: ERROR/AndroidRuntime(20662): java.lang.IllegalArgumentException: View not attached to window manager
09-19 22:27:24.209: ERROR/AndroidRuntime(20662): at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:355)
09-19 22:27:24.209: ERROR/AndroidRuntime(20662): at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:200)
09-19 22:27:24.209: ERROR/AndroidRuntime(20662): at android.view.Window$LocalWindowManager.removeView(Window.java:432)
09-19 22:27:24.209: ERROR/AndroidRuntime(20662): at android.app.Dialog.dismissDialog(Dialog.java:278)
09-19 22:27:24.209: ERROR/AndroidRuntime(20662): at android.app.Dialog.access$000(Dialog.java:71)
09-19 22:27:24.209: ERROR/AndroidRuntime(20662): at android.app.Dialog$1.run(Dialog.java:111)
09-19 22:27:24.209: ERROR/AndroidRuntime(20662): at android.app.Dialog.dismiss(Dialog.java:268)
09-19 22:27:24.209: ERROR/AndroidRuntime(20662): at android.app.Dialog.cancel(Dialog.java:951)
09-19 22:27:24.209: ERROR/AndroidRuntime(20662): at test.com.activities.ListActivity$Sincronizacao.onPostExecute(ListActivity.java:331)
09-19 22:27:24.209: ERROR/AndroidRuntime(20662): at android.os.AsyncTask.finish(AsyncTask.java:417)
09-19 22:27:24.209: ERROR/AndroidRuntime(20662): at android.os.AsyncTask.access$300(AsyncTask.java:127)
09-19 22:27:24.209: ERROR/AndroidRuntime(20662): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
09-19 22:27:24.209: ERROR/AndroidRuntime(20662): at android.os.Handler.dispatchMessage(Handler.java:99)
09-19 22:27:24.209: ERROR/AndroidRuntime(20662): at android.os.Looper.loop(Looper.java:143)
09-19 22:27:24.209: ERROR/AndroidRuntime(20662): at android.app.ActivityThread.main(ActivityThread.java:4701)
09-19 22:27:24.209: ERROR/AndroidRuntime(20662): at java.lang.reflect.Method.invokeNative(Native Method)
09-19 22:27:24.209: ERROR/AndroidRuntime(20662): at java.lang.reflect.Method.invoke(Method.java:521)
09-19 22:27:24.209: ERROR/AndroidRuntime(20662): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
09-19 22:27:24.209: ERROR/AndroidRuntime(20662): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
09-19 22:27:24.209: ERROR/AndroidRuntime(20662): at dalvik.system.NativeStart.main(Native Method)
But if I make the call natively like this (the menuitem is the third one):
mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);
mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_RIGHT);
mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_RIGHT);
mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_ENTER);
I don't get any errors no matter how many times I run the test. Why I'm getting that behaviour?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论