Saturday, March 24, 2012

[android-developers] getHits() succeeds but waitForActivityWithTimeout() returns null

Could someone please help me understand why in the code below assertEquals(1, monSettings.getHits()) succeeds but assertNotNull(activitySettings) fails?
WifiSettingsActivity starts fine, I can see it, but activitySettings is null. 
Is it because I'm starting an activity that is defined outside of the package under test?
If so, then I believe both asserts should fail.

Thank you in advance!

P.S. When I replace com.android.settings.Settings$WifiSettingsActivity with my own activity, the test succeeds.
P.P.S I tried startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS)), the activity also starts, but activitySettings is still null 
public void testWifiSettingsStarted() throws Throwable {
    final Intent intentSettings = new Intent();
    final ComponentName compSettings = new ComponentName("com.android.settings", "com.android.settings.Settings$WifiSettingsActivity");
    intentSettings.setComponent(compSettings);
    intentSettings.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    final ActivityMonitor monSettings = getInstrumentation().addMonitor("com.android.settings.Settings$WifiSettingsActivity", null, false);
    getInstrumentation().getContext().startActivity(intentSettings);
    final Activity activitySettings = monSettings.waitForActivityWithTimeout(10000);
    assertEquals(1, monSettings.getHits());
    assertNotNull(activitySettings);

    getInstrumentation().removeMonitor(monSettings);
}

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment