In my test Project all methods doesn’t have the annotation UiThreadTest, the advantage is that I can perform clicks and anything else and wait then with getInstrumentation().waitForIdleSync(); for the UI. But the disadvantage is that a button in my ui opens a dialog, which calls getActivity() in his constructor – this method returns null, because my test method has not the annotation UIThreadTest, when I add it then the dialog opens, but I can’t use waitForIdleSync.
So is there any equivalent code to wait for the ui with this annotation?
In my experience its good to limit your use of this annotation, what i tend to do is run any code that needs to interact with the Ui thread within a runnable the format is which:
you can then use the waitForIdleSync before and after any actions you do.