问题
In my App, I have a list view that shows all the currently installed apps in the system. Clicking on an item will select the next activity (one of the installed apps) to be launched.
I am trying to add a Activity Test for testing that this happens. I have an expandable list view that holds the list of installed apps.
// Get the child view of the list item that we want to launch
final View v = mExpListData.getChildView(0, launched_app_pos, false, null, null);
assertNotNull("Child List View Null", v);
mActivity.runOnUiThread(
new Runnable() {
public void run() {
// Click and launch temple run
mExpList.requestFocus();
}
}
);
getInstrumentation().waitForIdleSync();
TextView title = (TextView)v.
findViewById(com.example.demo.R.id.apkname);
assertNotNull("Title null", title);
assertEquals("App Name not correct", "Angry Birds", title.getText());
final int view_pos = 9;
mActivity.runOnUiThread(
new Runnable() {
public void run() {
// Click and launch temple run
mExpList.performItemClick(v, view_pos, view_pos);
} // end of run() method definition
} // end of anonymous Runnable object instantiation
); // end of invocation of runOnUiThread
getInstrumentation().waitForIdleSync();
Intent launchIntent =
mActivity.getPackageManager().getLaunchIntentForPackage(selectedApp.getPackageName());
// HOW TO I ADD A ACTIVITY MONITOR THAT WILL WAIT FOR THE ACTIVITY TO BE LAUNCHED
Any ideas?
I have added this as suggested below - still doesnt work
launchIntent.setAction(Intent.ACTION_MAIN);
final IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_MAIN);
ActivityMonitor mAppActivityMonitor = new ActivityMonitor(intentFilter, null, false);
mAppActivityMonitor.waitForActivityWithTimeout(TIMEOUT);
assertEquals(1, mAppActivityMonitor.getHits());
回答1:
You didn't set the action call intent.setAction(android.intent.action.MAIN);
来源:https://stackoverflow.com/questions/20469778/android-test-for-launching-activity-of-another-app