前名一个参数是应用程序的包名,后一个是这个应用程序的主Activity名
Intent intent=new Intent();
intent.setComponent(new ComponentName("com.droidnova.android.games.vortex",
"com.droidnova.android.games.vortex.Vortex"));
startActivity(intent);
这里第一个参数放包名也可以,放上下文也可以
其中包名和activity全路径的获取方法:
public static void initRouter(Context context) {
ActivityInfo[] activityInfos = null;
List<String> activityNames = new ArrayList<>();
PackageManager packageManager = context.getPackageManager();
try {
PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), PackageManager.GET_ACTIVITIES);
activityInfos = packageInfo.activities;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (activityInfos != null) {
for (ActivityInfo activityInfo : activityInfos) {
activityNames.add(activityInfo.name);
}
}
for (String activityName : activityNames) {
String[] splitStr = activityName.split("\\.");
routerMap.put(splitStr[splitStr.length - 1], activityName);
}
}
|