Auto restart service when apk crashes

I want to restart my service automatically if the application works. My ideas:

1: BroadcastReceiver when apk fails and service automatically restarts

if("android.intent.action.SOMETHING".equals(intent.getAction()))
  {
     Intent serviceLauncher = new Intent(context, Service.class);
     context.startService(serviceLauncher);
  }

2: with uncaughtException (), but I don't know how to handle this

+5
source share
3 answers

I think you only need to return START_STICKY in the onStartCommand () service

+5
source

Do you want your service to REALLY restart, or do you want to continue your service? I think that the service does not stop when the application crashes, the Service is separated from the application that creates it.

0
source

setUncaughtExceptionHandler

,

, ( ), StartService OnDestroy.

0

All Articles