[英]Wait for UI thread to finish
I am running an instrumentation Activity test. 我正在运行一个仪器活动测试。
In that I need to perform some UI operations in one of the UI elements of the Activity. 在那里,我需要在Activity的一个UI元素中执行一些UI操作。
So I am doing this in the UI thread of the Activity like this: 所以我在Activity的UI线程中这样做:
settingsActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
testSwitch.performClick();
}
});
Every time I am hit by can not perform this action after onSaveInstanceState
whenever the perform click is called. 每当我被命中时,无论何时调用执行点击, can not perform this action after onSaveInstanceState
。
A couple of things I have done: 我做过的几件事:
Thread.sleep()
after the code but it is not working. 我已经尝试将Thread.sleep()
放在代码之后,但它无法正常工作。 Cheers, Saurav 干杯,Saurav
just do one thing No call for super(). 只做一件事不要求super()。 I think its Bug on API Level > 11. 我认为它在API级别上的Bug> 11。
@Override
protected void onSaveInstanceState(Bundle outState) {
//No call for super(). Bug on API Level > 11.
}
or 要么
If you need to save the instance, and add something to your outState Bundle you can use the following : 如果需要保存实例,并在outState Bundle中添加一些内容,可以使用以下命令:
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putString("WORKAROUND_FOR_BUG_19917_KEY", "WORKAROUND_FOR_BUG_19917_VALUE");
super.onSaveInstanceState(outState);
}
Hope it will solve your problem. 希望它能解决你的问题。 Goood luck :) 好运:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.