Android 系统开机时间优化

    public static void setDefaultHome(Context context) {
        PackageManager packageManager = context.getPackageManager();
        final ComponentName component = Constants.HOME_COMPONENTNAME;
        final List<ResolveInfo> homeActivities = new ArrayList<>();
        packageManager.getHomeActivities(homeActivities);
        final List<ComponentName> allComponents = new ArrayList<>();
        for (ResolveInfo info : homeActivities) {
            final ActivityInfo appInfo = info.activityInfo;
            ComponentName activityName = new ComponentName(appInfo.packageName, appInfo.name);
            allComponents.add(activityName);
        }
        // 利用 PackageManager 设置默认主页
        packageManager.replacePreferredActivity(
                HOME_FILTER,
                IntentFilter.MATCH_CATEGORY_EMPTY,
                allComponents.toArray(new ComponentName[0]),
                component);

        // Launch the new Home app so the change is immediately visible even if
        // the Home button is not pressed.
        // 跳转到主页
        if (true) {
            // 不能再次启动 Launcher,影响开机时间,再次启动会多耗时 4s+
            return;
        }
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivityAsUser(intent, UserHandle.CURRENT);
    }
上一篇:Android实战开发篇 跳转自启动管理


下一篇:基于vueCli2发布一个vue组件的npm包