. , runOnUiThread(), NPE . , , .
, runOnUiThread , . , , , . , , UIEvent .
, CyclicBarrier, , , UiThread. encapuslate Activity.runOnUiThread() :
private void myRunOnUiThread( final Runnable r) {
final CyclicBarrier barrier = new CyclicBarrier(2);
mActivity.runOnUiThread(
new Runnable() {
public void run() {
r.run();
try { barrier.await(); } catch (Exception e) { e.printStackTrace(); }
}});
try { barrier.await(); } catch (Exception e) { e.printStackTrace(); }
}
:
public void testFieldUI() {
myRunOnUiThread(
new Runnable() {
public void run() {
mRateView.requestFocus();
mRateView.selectAll();
}
}
);
sendKeys(KeyEvent.KEYCODE_DEL);
assertTrue("rate is deleted", mRateView.getText().length() == 0);