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

Viewed 251

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, i.e. highest priority.

1 Answers
<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

Related