Android的进程优先级与进程回收

最近写了一个后台服务程序,大多数情况下都能正常运行,但在系统内存出现不足时,还是会被Android的low memory killer杀掉,在网上搜了下,找到了如下的解决方法:

完全让进程不被kill是不可能的,我们可以通过一些操作, 使进程被kill的几率变小:
1 提高进程的优先级:
后台操作采用Service形式,因为一个运行着service的进程比一个运行着后台activity的等级高。
2按back键使得进程中的activity在后台运行而不是destory,需重载back按键(没有任何activity在运行的进程优先被杀).
3依赖于其他优先级高的进程.
 
强制修改进程属性:
在程序中设置setPersistent(true);
在project的AndroidManifest.xml的<application>中加入属性android:persistent="true"
android:persistent(SDK)
    Whether or not the application should remain running at all times . The default value is "false". Applications should not normally set this flag; persistence mode is intended only for certain system applications(phone,system).

更多关于Android的进程优先级与进程回收的介绍,请参考下文:

http://blog.csdn.net/yk_hu0621/article/details/7085536

原文地址:https://www.cnblogs.com/alexrain/p/2358058.html