简体   繁体   中英

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

My app takes up too much 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. 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.

<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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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