diff --git a/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/WatchdogReceiver.java b/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/WatchdogReceiver.java index f490e9a9..bad60f8b 100644 --- a/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/WatchdogReceiver.java +++ b/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/WatchdogReceiver.java @@ -75,10 +75,14 @@ public void onReceive(Context context, Intent intent) { } if (!config.isManuallyStopped() && !isRunning) { - if (config.isForeground()) { - ContextCompat.startForegroundService(context, new Intent(context, BackgroundService.class)); - } else { - context.startService(new Intent(context, BackgroundService.class)); + try { + if (config.isForeground()) { + ContextCompat.startForegroundService(context, new Intent(context, id.flutter.flutter_background_service.BackgroundService.class)); + } else { + context.getApplicationContext().startService(new Intent(context, id.flutter.flutter_background_service.BackgroundService.class)); + }} + catch (Exception e){ + e.printStackTrace(); } } }