how can you tell when an Android activity is finished loading?

Derrick picture Derrick · Jan 18, 2010 · Viewed 21.3k times · Source

I'm in the process of working on an automated test suite for our android app, and running into trouble waiting for activities to fully load. I can call getActivity, but just because it shows the activity that I'm hoping to see in my test doesn't always seem to mean that the activity's components are ready for use (fully loaded). Looking through the Activity API didn't turn anything up, and other methods seem too invasive and have spoiled the tests initial state. Does anyone know if there's a way to ask the app or the VM if the current activity is loaded?

Answer

Christopher Orr picture Christopher Orr · Jan 19, 2010

As I mentioned in a comment, your view hierarchy should be working after your call to setContentView() early in onCreate(). I've never had any problems like this with any activity or test class..

I'm not sure this is of any help for this specific case, but in general you can determine when the UI event queue is empty by calling getInstrumentation().waitForIdleSync(). That'll block until there's no more UI events to process.