From 3770091b58eddaa920af7b34901b4fff55d6b1ce Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Tue, 20 May 2025 11:32:20 +0500 Subject: [PATCH] mobile: handle crash in background on device boot --- .../notesnook/BootRecieverService.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/apps/mobile/native/android/app/src/main/java/com/streetwriters/notesnook/BootRecieverService.java b/apps/mobile/native/android/app/src/main/java/com/streetwriters/notesnook/BootRecieverService.java index 519f289d0..5768ce6af 100644 --- a/apps/mobile/native/android/app/src/main/java/com/streetwriters/notesnook/BootRecieverService.java +++ b/apps/mobile/native/android/app/src/main/java/com/streetwriters/notesnook/BootRecieverService.java @@ -14,19 +14,21 @@ public class BootRecieverService extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - if (!isAppOnForeground((context))) { - /** - We will start our service and send extra info about - network connections - **/ - Intent serviceIntent = new Intent(context, BootTaskService.class); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - context.startForegroundService(serviceIntent); - } else { - context.startService(serviceIntent); - } - HeadlessJsTaskService.acquireWakeLockNow(context); - } + try { + if (!isAppOnForeground((context))) { + /** + We will start our service and send extra info about + network connections + **/ + Intent serviceIntent = new Intent(context, BootTaskService.class); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + context.startForegroundService(serviceIntent); + } else { + context.startService(serviceIntent); + } + HeadlessJsTaskService.acquireWakeLockNow(context); + } + } catch (Exception ignored) {} } private boolean isAppOnForeground(Context context) {