美文网首页
避免进程被kill

避免进程被kill

作者: 傀儡世界 | 来源:发表于2017-06-06 11:48 被阅读28次

1.在Service的onDestroy()中重启Service,或者广播中

public void onDestroy()
{
Intent localIntent = new Intent();
localIntent.setClass(this, MyService.class); // 销毁时重新启动Service
this.startService(localIntent);
}

在一段时间后才会启动

2.提升service的优先级,程序签名,或adb push到system\app。在其Manifest.xml文件中设置persistent属性为true,则可使其免受out-of-memory killer的影响,永久性应用。

<application android:name="PhoneApp"
       android:persistent="true"
       android:label="@string/dialerIconLabel"
       android:icon="@drawable/ic_launcher_phone">
   ...
</application>

保证进程不被kill

详解链接:说说Android应用的persistent属性

相关文章

网友评论

      本文标题:避免进程被kill

      本文链接:https://www.haomeiwen.com/subject/jhugfxtx.html