好吧......这是更可能是我的错;)
Ok...it is more likely to be my fault ;)
当我做的:
public class XmlLifecycleTests extends ActivityUnitTestCase<Main> {
...
(not in setUp)
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setPackage(APP_PACKAGE);
intent.setClassName(APP_PACKAGE, ".gui.Main");
startActivity(intent, null, null);
我得到:
java.lang.IllegalArgumentException: android.content.pm.PackageManager$NameNotFoundException: ComponentInfo{ar.android.app.gui/ar.android.app.gui.GLarmMain}
at android.support.v4.app.NavUtils.getParentActivityName(NavUtils.java:282)
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:119)
at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
at ar.android.app.gui.Main.onCreate(Main.java:78)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.test.ActivityUnitTestCase.startActivity(ActivityUnitTestCase.java:158)
请注意,我的主要活动是在.gui定义,而主包中的清单是一个文件夹了,这就是为什么我指定所有的意图。但抛出的错误似乎仍然得到了错误的(包,类)的名称对。
Note that my Main activity is defined under .gui while the main package in the manifest is one folder up, this is why I specified everything in the intent. But the thrown error seems to still get the wrong (Package,Class) name pair.
这确实是我的错......切换 startActivity
来:
It was indeed my fault...switching startActivity
to:
setActivity(launchActivity(PKG,actClass,NULL));
解决我所有的问题。