How to restart a killed service automatically?

后端 未结 3 587
死守一世寂寞
死守一世寂寞 2020-12-18 03:13

When a service has been killed, how to restart it automatically?

sometimes without even calling onDestroy()

3条回答
  •  甜味超标
    2020-12-18 04:09

    I inherited an IntentService, so I had to be gentle. It worked for me when I overrode onStartCommand() but

    public int onStartCommand(Intent intent, int flags, int startId) {
       super.onStartCommand(intent, flags, startId);
       return START_STICKY;
    }
    

    That is, let the parent do what it should and return START_STICKY.

提交回复
热议问题