单元测试时遇到的问题,执行的操作本应该弹出悬浮框,实际却没有,并报错:
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
这是因为更新UI的操作需要放到UI线程里:
runOnUiThread(new Runnable() {
@Override
public void run() {
//更新UI的操作
}
});
runOnUiThread是Activity的一个方法,文档见:http://developer.android.com/reference/android/app/Activity.html#runOnUiThread(java.lang.Runnable)
参考:http://stackoverflow.com/questions/5161951/android-only-the-original-thread-that-created-a-view-hierarchy-can-touch-its-vi