There is one way to set the app to never be killed, AndroidManifest. add: android: persistent = "true" to the xml file. After the app is set in/system/app, the app is upgraded to the system core level without being killed, the stop operation is also blocked in settings-> applications. Proc #19: adj = svc/B 4067b028 255: com. xxx. xxx/10001 (started-services) # cat/proc/255/oom_adj4 after setting PERS #19: adj = core/F 406291f0 155: com. xxx. xxx/10001 (fixed) # cat/proc/155/oom_adj-12 lowmemorykiller operation rules such as write/sys/module/lowmemorykiller/parameters/adj, 2, 4, write/sys/module/lowmemorykiller/parameters/minfree 2048,3072, 4096, 6144, 7168, 8192 can be seen. After persistent is set, oom_adj =-12, there is no chance to be processed by lowmemorykiller: persistent Whether or not the application shocould remain running at all times-"true" if it shocould, and "false" if not. the default value is "false ". applications shocould not normally set this flag; persistence mode is intended only for certain system applications code
ActivityManagerService.java final ProcessRecord addAppLocked(ApplicationInfo info) { ProcessRecord app = getProcessRecordLocked(info.processName, info.uid); if (app == null) { app = newProcessRecordLocked(null, info, null); mProcessNames.put(info.processName, info.uid, app); updateLruProcessLocked(app, true, true); } if ((info.flags&(ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PERSISTENT)) == (ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PERSISTENT)) { app.persistent = true; app.maxAdj = CORE_SERVER_ADJ; } if (app.thread == null && mPersistentStartingProcesses.indexOf(app) < 0) { mPersistentStartingProcesses.add(app); startProcessLocked(app, "added application", app.processName); } return app; }
You can see the app that meets both the FLAG_SYSTEM (/system/app directory) and FLAG_PERSISTENT (android: persistent = "true"), and set the app. maxAdj = CORE_SERVER_ADJ (-12), whereas adj =-12 won't be processed by lowmemorykiller