避免进程被kill

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属性

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容