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已经不行了

 

相关文章:

  • 2021-10-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-09
  • 2021-10-08
  • 2021-05-30
猜你喜欢
  • 2021-07-10
  • 2021-05-29
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
  • 2021-11-15
  • 2022-02-09
相关资源
相似解决方案