先创建个intent,再通过inten.resolveActivityInfo向PackageManager查找对应activity的信息,PackageManager在被SystemServer创建初始化时会从系统中扫描当前系统已安装的所有apk信息并保存。
intent.resolveActivityInfo
如HOME启动:
创建一个CATEGORY_HOME类型的Intent,然后通过Intent.resolveActivityInfo函数向PackageManagerService查询Category类型为HOME的Activity。
intent.addCategory(Intent.CATEGORY_HOME); //intent.setClassName("com.xx.bootactivity", "com.xx.bootactivity.BootActivity"); ActivityInfo aInfo = intent.resolveActivityInfo(mContext.getPackageManager(), STOCK_PM_FLAGS); if (aInfo != null) { intent.setComponent(new ComponentName( aInfo.applicationInfo.packageName, aInfo.name)); // Don't do this if the home app is currently being // instrumented. ProcessRecord app = getProcessRecordLocked(aInfo.processName, aInfo.applicationInfo.uid); if (app == null || app.instrumentationClass == null) { intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK); mMainStack.startActivityLocked(null, intent, null, null, 0, aInfo, null, null, 0, 0, 0, false, false, null); }