1.Android 进程回收策略

众所周知,Android是基于Linux系统的。在Android进程回收策略中,Android进程与Linux进程根据OOM_ADJ阈值进行区分:

  • OOM_ADJ >= 4:比较容易被杀死的进程
  • OOM_ADJ 0 ~ 3:不容易被杀死的进程
  • OOM_ADJ < 0 :纯Linux进程,非Android进程
当Android系统察觉设备内存不足时,会按照阈值从大到小杀死进程。
 
具体的oom_adj值的意义我们可以查看AOSP中的com.android.server.am.ProcessList 文件(其中本人添加了一些中文注释):
/**
* Activity manager code dealing with processes.
*/
final class ProcessList {
... // OOM adjustments for processes in various states: // Adjustment used in certain places where we don't know it yet.
// (Generally this is something that is going to be cached, but we
// don't know the exact value in the cached range to assign yet.)
// 未知进程,通常是用作缓存
static final int UNKNOWN_ADJ = ; // This is a process only hosting activities that are not visible,
// so it can be killed without any disruption.
// 拥有不可视的Activity的进程,可以不影响影响用户的情况下杀掉
static final int CACHED_APP_MAX_ADJ = ;
static final int CACHED_APP_MIN_ADJ = ; // The B list of SERVICE_ADJ -- these are the old and decrepit
// services that aren't as shiny and interesting as the ones in the A list.
// 一些旧的服务进程
static final int SERVICE_B_ADJ = ; // This is the process of the previous application that the user was in.
// This process is kept above other things, because it is very common to
// switch back to the previous app. This is important both for recent
// task switch (toggling between the two top recent apps) as well as normal
// UI flow such as clicking on a URI in the e-mail app to view in the browser,
// and then pressing back to return to e-mail.
// 用户使用的前一个进程
static final int PREVIOUS_APP_ADJ = ; // This is a process holding the home application -- we want to try
// avoiding killing it, even if it would normally be in the background,
// because the user interacts with it so much.
// 主界面进程
static final int HOME_APP_ADJ = ; // This is a process holding an application service -- killing it will not
// have much of an impact as far as the user is concerned.
// 持有应用服务的进程
static final int SERVICE_ADJ = ; // This is a process with a heavy-weight application. It is in the
// background, but we want to try to avoid killing it. Value set in
// system/rootdir/init.rc on startup.
// 重量级应用进程
static final int HEAVY_WEIGHT_APP_ADJ = ; // This is a process currently hosting a backup operation. Killing it
// is not entirely fatal but is generally a bad idea.
// 执行备份操作的进程
static final int BACKUP_APP_ADJ = ; // This is a process only hosting components that are perceptible to the
// user, and we really want to avoid killing them, but they are not
// immediately visible. An example is background music playback.
// 拥有用户可感知组件的进程
static final int PERCEPTIBLE_APP_ADJ = ; // This is a process only hosting activities that are visible to the
// user, so we'd prefer they don't disappear.
// 拥有用户仅可见、不可交互的Activity的进程
static final int VISIBLE_APP_ADJ = ; // This is the process running the current foreground app. We'd really
// rather not kill it!
// 前台运行的进程
static final int FOREGROUND_APP_ADJ = ; // This is a system persistent process, such as telephony. Definitely
// don't want to kill it, but doing so is not completely fatal.
// 系统常驻进程
static final int PERSISTENT_PROC_ADJ = -; // The system process runs at the default adjustment.
// 系统进程
static final int SYSTEM_ADJ = -; // Special code for native processes that are not being managed by the system (so
// don't have an oom adj assigned by the system).
// 为native进程保留,他们不被系统管理
static final int NATIVE_ADJ = -; ...
}

2.Android 进程被杀死情况

一般来说,Android进程被杀死有以下几种情况:
  1. 触发系统进程管理机制回收(Lowmemorykiller):这种方法会按照阈值从大到小进行清理
  2. 被没有进行Root的第三方应用杀死(使用killBackgroundProcess方法):这种方法只能杀死OOM_ADJ为4以上的进程
  3. 被进行Root的第三方应用杀死(使用force-stop或者kill):理论上来说可以杀死所有进程,但一般只会清理非系统关键进程和非前台可见进程
  4. 厂商的杀进程功能(force-stop或者kill):理论上来说可以杀死所有进程,包括Linux原生进程
  5. 用户主动“强行停止”进程(force-stop):只能停用第三方和非system/phone进程应用(停用system进程应用会造成Android系统重启)

最新文章

  1. Lua 栈的理解
  2. http学习笔记(三)
  3. nlog(n)解动态规划--最长上升子序列(Longest increasing subsequence)
  4. VC6.0中MFC界面换肤简例
  5. xib中设置控件的圆角
  6. UIStepper
  7. SqlServr进程内存使用增长的解决办法
  8. 一、JSP、Servlet 概要
  9. Ajax之旅(一)--什么是Ajax
  10. JOSM学习下载地址
  11. python matplotlib 播放图片变化过程
  12. js 遍历 each() 方法
  13. 玩玩小程序:使用 WebApi 交互打造原生的微信小程序 - 图灵小书架
  14. 《React Native 精解与实战》书籍连载「React Native 源码学习方法及其他资源」
  15. oracle xe在centos下的安装(更)
  16. 基于BeautifulSoup库的HTML内容的查找
  17. 100-days: fifteen
  18. B - Modular Inverse
  19. 关于cc -o命令
  20. JUnit注解

热门文章

  1. rabbitmq系列二 之工作队列
  2. 页面按钮埋点+跟踪location.search
  3. EF 通过DataAnnotations配置属性和类型
  4. 搭建hadoop_之 创建3个虚拟机配置好网络
  5. invokespecial与invokevirtual指令的区别
  6. Jfinal本地eclipse+tomcat运行项目时候遇到错误Exception starting filter
  7. Innosetup(pascal)标签控件label换行
  8. attempt to write a readonly database错误的解决(C#,SQLite)
  9. Eureka Server项目启动报错处理
  10. 转载:SQL中的case when then else end用法