Android释放内存(结束进程)
??这两天在搞个内存清理小插件,网上很少这方面资料,之前找过清理缓存的例子测试,结果不成功。后来自己思考该怎么清理内存,于是成功搞出来了。
2.2以上的用killBackgroundProcesses(包名); ? ?对应权限<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
之前我以为可用android.os.Process.killProcess(pid);来杀掉其他进程,后来发觉不行
网上找到的解析是
对于这个方法,需要详细解释一下。在SDK的文档中,解释如下:
Kill the process with the given PID. Note that, though this API allows us to request to kill any process based on its PID, the kernel will still impose standard restrictions on which PIDs you are actually able to kill. Typically this means only the process running the caller's packages/application and any additional processes created by that app; packages sharing a common UID will also be able to kill each other's processes.
英语不好,不能准确翻译,所以希望大家自己理解,免得对大家造成误解。我个人对这句话的解释就是,这个方法使用是有条件的:
a、将被杀掉的进程 和 当前进程 处于同一个包或者应用程序中;
b、将被杀掉的进程 是由当前应用程序所创建的附加进程;
c、将被杀掉的进程 和 当前进程 共享了普通用户的UID。(这里的普通用户,是相对于Root权限的用户来说的)
1 楼 happyboy858 2012-01-18 楼主, 真心求源码 QQ:441667111@qq.com thanks.