您的位置:首页 > 移动开发 > Android开发

Android防止进程被杀

2016-06-06 18:18 447 查看
有时开启新的app而内存不够时,其它app可能会被Out
Of Memory Killer清除防止进程不被杀死的办法:

1.在AndroidManifest.xml文件中设置persistent属性为true

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:persistent="true">
2.在前端运行程序

private void startForeground() {
Notification notification = new NotificationCompat.Builder(this)
.setContentTitle(getResources().getString(R.string.app_name))
.setTicker(getResources().getString(R.string.app_name))
.setContentText("Running")
.setSmallIcon(R.drawable.unlock)
.setContentIntent(null)
.setOngoing(true)
.build();
startForeground(9999,notification);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: