One way is to set the app to never be killed. Add Android: Persistent = "true" to androidmanifest. xml"
Applicable to apps stored in/system/APPAfter setting, the app is upgraded to the core level of the system and will not be killed in any case. The stop operation will also be blocked in settings-> applications. Proc #19 before setting: 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
The lowmemorykiller operation rule is as follows:
Write/sys/module/lowmemorykiller/parameters/adj
Write/sys/module/lowmemorykiller/parameters/minfree 2048,3072, 4096,6144, 7168,8192
After persistent is set, oom_adj =-12 will never be processed by lowmemorykiller.
Android: 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; }
The flag_system (/system/APP directory) and flag_persistent (Android: Persistent = "true ")
APP, set app. maxadj = core_server_adj (-12), and adj =-12 won't be processed by lowmemorykiller