title: How can I wait for an Activity to load its views in Robotium?
body: <p>I'm having a problem with Robotium where waitForActivity completes when an activity is loaded, but the views on it are not yet accessible.  For example:</p>
  
  <pre><code>solo.clickOnButton("Go");
  assertTrue(solo.waitForActivity("ActivityTest", 5000));
  Activity a = solo.getCurrentActivity();  // This works - a is "ActivityTest"
  ArrayList&lt;View&gt; v = solo.getViews();     // This doesn't work - v is empty
  </code></pre>
  
  <p>The issue seems to be that the activity hasn't completely loaded; a sleep delay works around the problem:</p>
  
  <pre><code>solo.clickOnButton("Go");
  assertTrue(solo.waitForActivity("ActivityTest", 5000));
  Activity a = solo.getCurrentActivity();  // This works - a is "ActivityTest"
  solo.sleep(5000);
  ArrayList&lt;View&gt; v = solo.getViews();     // This works - v has lots of views
  </code></pre>
  
  <p>Is this just a fact of life with Robotium or am I doing this wrong?  </p>
  
  <p>edit: This is what I am now using in place of solo.waitForActivity:</p>
  
  <pre><code>public Boolean waitForActivity(String name) {
      int timeout = 10 * 1000; 
      long start = Calendar.getInstance().getTimeInMillis();
      assertTrue(solo.waitForActivity(name, timeout));
      solo.assertCurrentActivity(name, name);
      ArrayList&lt;View&gt; views = solo.getViews();
      while (views.isEmpty()) {
          solo.sleep(1000);
          views = solo.getViews();
          if (Calendar.getInstance().getTimeInMillis() &gt; start + timeout)
      return false;
      }
      return true;
  }
  </code></pre>