如何让自己的app尽量不被系统杀死

1.

在Service中重写下面的方法,这个方法有三个返回值, START_STICKY是service被kill掉后自动重写创建 

@Override 
public int onStartCommand(Intent intent, int flags, int startId) { 
  return START_STICKY; 
}

2.

在Service的onDestroy()中重启Service. 

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

3.

在mf.xml的application的节点中添加android:persistent="true"

这个方法,必须要system app,所以这个基本没用

4.

fork进程的方式做守护,在5.0已经不行了

 

转载于:https://www.cnblogs.com/supermanChao/p/5749799.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值