高通Android 12/13添加/移除不被清理后台应用


    /**
     * 添加不被清理的后台应用
     *
     * @param packageName
     */
    public void addBackgroundAliveApp(String packageName) {
        List<String> list = getBackgroundAliveAppList();
        if (list != null && packageName != null && packageName.length() > 0) {
            if (!list.contains(packageName)) {
                list.add(packageName);
            }
            setBackgroundAliveAppList(list);
        }
    }

    /**
     * 移除不被清理的后台应用
     *
     * @param packageName
     */
    public void removeBackgroundAliveApp(String packageName) {
        List<String> list = getBackgroundAliveAppList();
        if (list != null && packageName != null && packageName.length() > 0) {
            if (list.contains(packageName)) {
                list.remove(packageName);
            }
            setBackgroundAliveAppList(list);
        }
    }

    /**
     * 获取不被清理的后台应用列表
     *
     * @return
     */
    public List<String> getBackgroundAliveApps() {
        List<String> list = getBackgroundAliveAppList();
        return list;
    }

补充代码

   public static List<String> getWhiteAppProcessList() {
        List<String> list = new ArrayList();

        String sizeKey = "persist.test.aliveapps_s";
        String valKey = "persist.test.aliveapps_";
        int size = 0;
        try
        {
            size = Integer.parseInt(SystemProperties.get(sizeKey));
        }
        catch(Exception e)
        {
        }
        if(size>0)
        {
            for(int i=0;i<size;i++)
            {
                list.add(SystemProperties.get(valKey+i));
            }
        }
        return list;
    }

    public static void setWhiteAppProcessList(List<String> whiteAppProcessList) {
        if(whiteAppProcessList==null || whiteAppProcessList.size()==0)
        {
            whiteAppProcessList = new ArrayList();
        }


        String sizeKey = "persist.test.aliveapps_s";
        String valKey = "persist.test.aliveapps_";
        int orgSize = 0;
        try
        {
            orgSize = Integer.parseInt(SystemProperties.get(sizeKey));
        }
        catch(Exception e)
        {

        }
        if (orgSize > 0) {
            for(int i=0;i<orgSize;i++)
            {
                SystemProperties.set(valKey+i,"");
            }
        }

        int size = whiteAppProcessList.size();
        SystemProperties.set(sizeKey,String.valueOf(size));
        for(int i=0;i<size;i++)
        {
            SystemProperties.set(valKey+i,whiteAppProcessList.get(i));
        }

    }


    public static List<String> getBackgroundAliveAppList() {

        String sizeKey = "persist.test.backgroundapps_s";
        String valKey = "persist.test.backgroundapps_";
        List<String> list = new ArrayList();
        int size = 0;
        try
        {
            size = Integer.parseInt(SystemProperties.get(sizeKey));
        }
        catch(Exception e)
        {
        }
        if(size>0)
        {
            for(int i=0;i<size;i++)
            {
                list.add(SystemProperties.get(valKey+i));
            }
        }
        return list;
    }

    public static void setBackgroundAliveAppList(List<String> backgroundAliveAppList) {
        if(backgroundAliveAppList==null || backgroundAliveAppList.size()==0)
        {
            backgroundAliveAppList = new ArrayList();
        }

        String sizeKey = "persist.test.backgroundapps_s";
        String valKey = "persist.test.backgroundapps_";
        int orgSize = 0;
        try
        {
            orgSize = Integer.parseInt(SystemProperties.get(sizeKey));
        }
        catch(Exception e)
        {

        }
        if (orgSize > 0) {
            for(int i=0;i<orgSize;i++)
            {
                SystemProperties.set(valKey+i,"");
            }
        }

        int size = backgroundAliveAppList.size();
        SystemProperties.set(sizeKey,String.valueOf(size));
        for(int i=0;i<size;i++)
        {
            SystemProperties.set(valKey+i,backgroundAliveAppList.get(i));
        }

    }

转载请注明出处高通Android 12/13添加/移除不被清理后台应用-CSDN博客,谢谢!

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-10 06:28:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-10 06:28:01       106 阅读
  3. 在Django里面运行非项目文件

    2024-06-10 06:28:01       87 阅读
  4. Python语言-面向对象

    2024-06-10 06:28:01       96 阅读

热门阅读

  1. Docker面试整理-Docker Swarm与Kubernetes有什么区别?

    2024-06-10 06:28:01       29 阅读
  2. EF Core Model-First

    2024-06-10 06:28:01       26 阅读
  3. SOA的设计模式_1.服务注册表模式

    2024-06-10 06:28:01       30 阅读
  4. 209. 长度最小的子数组

    2024-06-10 06:28:01       35 阅读
  5. 主从式光伏并网发电系统体系结构

    2024-06-10 06:28:01       25 阅读
  6. ICESat-2 ATL08 数据批量读取

    2024-06-10 06:28:01       45 阅读
  7. 发布自己的 npm 插件包:步骤与最佳实践

    2024-06-10 06:28:01       37 阅读