title: Espresso and postDelayed
body: <p>I have an activity which is using a postDelayed call:</p>
  
  <pre><code>public class SplashActivity extends Activity {
      private Handler handler = new Handler();
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(...);
          handler.postDelayed(new Runnable() { 
              public void run() { finish(); }
          }, 3000L);
      }
   }
  </code></pre>
  
  <p>This runs at app startup, and i need to navigate it and my login screen.  However, the UIController's loopMainThreadUntilIdle doesn't seem to take the underlying MessageQueue in the handler into account.  As such, this action finishes immediately while there is still messages in the queue. </p>
  
  <pre><code>onView(withId(R.id.splash_screen)).perform(new ViewAction() {
      @Override
      public Matcher&lt;View&gt; getConstraints() {
          return isAssignableFrom(View.class);
      }
  
      @Override
      public String getDescription() {
          return "";
      }
  
      @Override
      public void perform(final UiController uiController, final View view) {
          uiController.loopMainThreadUntilIdle();
      }
  });
  </code></pre>
  
  <p>I've been unable to figure out how to block until the queue is drained.  Android itself is preventing me from doing a lot of things i would have tried (like extending Handler and overriding the postDelayed method, etc...)</p>
  
  <p>Anyone have any suggestions on how to handle postDelayed?</p>
  
  <p>I'd rather avoid uiController.loopMainThreadForAtLeast, which seems hacky (like a Thread.sleep would) </p>