I tried starting different activities using the code below. The test always succeeds if an activity I'm starting is defined in the package under test, which is in turn defined by the <instrumentation/> tag in AndroidManifest.xml But as soon as I try to start an activity that is defined outside of the package under test, waitForActivityWithTimeout() always returns null even though AcitivityMonitor.getHits() returns hit count of 1. And it does not matter whether an activity is started in the parent's activity taks or in the new task - the result is the same. Is this what we should expect? Can't a test access an activity that is defined outside of the package under test?
Thank you! private Activity testActivityStarted(String pkg, String cls, Activity > parent) throws Throwable { > final Intent intent = new Intent(); > final ComponentName compName = new ComponentName(pkg, cls); > intent.setComponent(compName); > final ActivityMonitor mon = getInstrumentation().addMonitor(cls, null, > false); > if(parent == null) { > intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getInstrumentation().getContext().startActivity(intent); } > else { > parent.startActivity(intent); } > final Activity activity = mon.waitForActivityWithTimeout(10000); > * assertEquals(1, mon.getHits()); > assertNotNull(activity); > * getInstrumentation().removeMonitor(mon); > return activity; > } 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