在我的应用程序中,我有一个列表视图,显示系统中所有当前安装的应用程序。单击某个项目将选择要启动的下一个活动(已安装的应用程序之一)。
我正在尝试添加一个Activity Test来测试这种情况。我有一个可扩展的列表视图,其中包含已安装的应用程序列表。
// 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
有什么想法吗?
我已经按照以下建议添加了这个 - 仍然无法正常工作
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());
答案 0 :(得分:0)
你没有设置动作调用intent.setAction(android.intent.action.MAIN);