简体   繁体   English

你如何改变无障碍服务的运行过程?

[英]How do you change the process an accessibility service is running in?

My app takes up too much RAM.我的应用程序占用了太多 RAM。 I found that placing the accessibility service in a different process will prevent it from being shut down alongside the app.我发现将无障碍服务放在不同的进程中会阻止它与应用程序一起关闭。 It also apparently has the added benefit that if the app crashes then the accessibility service won't crash along with it.它显然还有一个额外的好处,即如果应用程序崩溃,那么无障碍服务不会随之崩溃。

I tried just adding android:process=":externalProcess" under the accessibility service in the manifest file but that doesn't work.我尝试在清单文件的可访问性服务下添加android:process=":externalProcess"但这不起作用。 How do I do it?我该怎么做? Also one more question, how do I inform the OS that no matter how much RAM the accessibility service is taking it should never be shut down, ie highest priority.还有一个问题,我如何通知操作系统无论无障碍服务占用多少 RAM,都不应关闭它,即最高优先级。

<uses-permission  android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>

Request White-list / optimization enabled your app请求白名单/优化启用您的应用

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        Intent intent = new Intent();
        String packageName = getPackageName();
        PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
        if (!pm.isIgnoringBatteryOptimizations(packageName)) {
            intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
            intent.setData(Uri.parse("package:" + packageName));
            startActivity(intent);
        }
    }

If this won't help in your case, try to use this library: https://github.com/iardelian/Revive-S如果这对您没有帮助,请尝试使用此库: https://github.com/iardelian/Revive-S

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM