Android: 怎樣設定app不被系統k掉

來源:互聯網
上載者:User

有一種方法可以設定app永遠不會被kill,AndroidManifest.xml 中添加: android:persistent="true"適用於放在/system/app下的app 設定後app提升為系統核心層級,任何情況下不會被kill掉, settings->applications裡面也會屏蔽掉stop操作,設定前 Proc #19: adj=svc  /B 4067b028 255:com.xxx.xxx/10001 (started-services)# cat /proc/255/oom_adj4設定後 PERS #19: adj=core /F 406291f0 155:com.xxx.xxx/10001 (fixed)# cat /proc/155/oom_adj-12 lowmemorykiller的操作規則比如為write /sys/module/lowmemorykiller/parameters/adj 0,1,2,4,7,15write /sys/module/lowmemorykiller/parameters/minfree 2048,3072,4096,6144,7168,8192 可以看到,設定persistent後, oom_adj=-12,永遠沒有機會被lowmemorykiller處理 android:persistent Whether or not the application should remain running at all times — "true" if it should, and "false" if not. The default value is "false". Applications should not normally set this flag; persistence mode is intended only for certain system applications 代碼 

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;      }  

 

 可以看到同時符合FLAG_SYSTEM(/system/app目錄)及FLAG_PERSISTENT(android:persistent="true")的app,設定app.maxAdj = CORE_SERVER_ADJ(-12),而adj=-12不會被lowmemorykiller處理 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.