执行以下代码Activity
后,我的应用程序将关闭,但直到组件名称,代码工作正常:
PackageManager pm = getPackageManager();
PackageInfo packageInfo = pm.getPackageInfo("com.package.address",PackageManager.GET_ACTIVITIES);
ActivityInfo[] activitiesInfos = packageInfo.activities;
ActivityInfo activityToLaunch=activitiesInfos[0]; //<< activity which want enter code here to enter code herestart
// Create ComponentName object using packageName and activity name
ComponentName compName=new ComponentName(
activityToLaunch.applicationInfo.packageName,
activityToLaunch.name);
Intent intent=new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(compName);
startActivity(intent);
调试光标到startActivity(intent)
但在此活动结束后
答案 0 :(得分:2)
好的,请尝试以下:
1。)如果你只是想启动另一个应用程序的启动器活动:
Intent intent = getPackageManager().getLaunchIntentForPackage("com.package.address");
if (intent != null) {
// if package is found; otherwise null
startActivity(intent);
}
2。)如果你想开始一个特定的活动(注意:你需要知道它的全名,并且应该在AndroidManifest中设置android:exported="true"
)
Intent intent = new Intent();
// xxx and yyy representing its sub package if any
intent.setComponent(new ComponentName("com.package.address", "com.package.address.xxx.yyy.FullActivityName"));
startActivity(intent);