`
icheng
  • 浏览: 829234 次
  • 性别: Icon_minigender_1
  • 来自: 珠海
文章分类
社区版块
存档分类
最新评论

Android: HowTo设置app不被系统kill掉

 
阅读更多
有一种方法可以设置app永远不会被kill,AndroidManifest.xml 中添加:
android:persistent="true"
适用于放在/system/app下的app
设置后app提升为系统核心级别,任何情况下不会被kill掉, settings->applications里面也会屏蔽掉stop操作,
设置前 Proc#19:adj=svc/B4067b028255:com.xxx.xxx/10001(started-services)
#cat/proc/255/oom_adj
4
设置后 PERS#19:adj=core/F406291f0155:com.xxx.xxx/10001(fixed)
#cat/proc/155/oom_adj
-12

lowmemorykiller的操作规则比如为

write /sys/module/lowmemorykiller/parameters/adj 0,1,2,4,7,15

write /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

代码


可以看到同时符合FLAG_SYSTEM(/system/app目录)及FLAG_PERSISTENT(android:persistent="true")

的app,设置app.maxAdj = CORE_SERVER_ADJ(-12),而adj=-12不会被lowmemorykiller处理

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics