I want to restart my Service automatically if the application crashes. My ideas are:
1: a BroadcastReceiver when the apk crashes and automatic restart the Service
if("android.intent.action.SOMETHING".equals(intent.getAction()))
{
Intent serviceLauncher = new Intent(context, Service.class);
context.startService(serviceLauncher);
}
2: with an uncaughtException(), but i dont know to handle that
I think you only need return START_STICKY in onStartCommand() of Service
You can use setUncaughtExceptionHandler
When receiving the event you can start the service again,
Another option, that might work (You need to try it), is calling StartService on the OnDestroy method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With