More information: I also have a test that clicks a an email link on an emulator where more than one email client is installed. When a test clicks on the link, a chooser activity is launched. The chooser activity is defined outside of the package under test, and yet the test CAN access it. Clearly, the test can access an activity that is defined outside the package under test. But why can it access the activity when it is launched indirectly through a view click and cannot access the activity when it is launched directly through startActivity() call?
This is very inconsistent behavior. Does anyone have thoughts on this? Thank you! P.S. The sample below is the one that works fine. The chooser activity is returned and can be finished. *contact* variable is a TextView that contains an email link created by Linkify library. final ActivityMonitor mon = getInstrumentation().addMonitor(" > com.android.internal.app.ChooserActivity", null, false); > TouchUtils.tapView(this, contact); > final Activity chooserActivity = mon.waitForActivityWithTimeout(10000); > *assertNotNull(chooserActivity); > **chooser**Activity.finish();* On Saturday, March 24, 2012 8:25:02 AM UTC-7, Y2i wrote: > > 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en