From f083546c7c28edc6ec0fb8751b41144d0253c800 Mon Sep 17 00:00:00 2001 From: ardocrat Date: Wed, 1 May 2024 01:23:46 +0300 Subject: [PATCH] android: update notification less frequently --- .../main/java/mw/gri/android/BackgroundService.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/android/app/src/main/java/mw/gri/android/BackgroundService.java b/android/app/src/main/java/mw/gri/android/BackgroundService.java index 99f3892..ea6b910 100644 --- a/android/app/src/main/java/mw/gri/android/BackgroundService.java +++ b/android/app/src/main/java/mw/gri/android/BackgroundService.java @@ -21,6 +21,8 @@ public class BackgroundService extends Service { private static final int SYNC_STATUS_NOTIFICATION_ID = 1; private NotificationCompat.Builder mNotificationBuilder; + private String mNotificationContentText = ""; + private final Runnable mUpdateSyncStatus = new Runnable() { @Override public void run() { @@ -28,9 +30,13 @@ public class BackgroundService extends Service { return; } // Update sync status at notification. - mNotificationBuilder.setContentText(getSyncStatusText()); - NotificationManager manager = getSystemService(NotificationManager.class); - manager.notify(SYNC_STATUS_NOTIFICATION_ID, mNotificationBuilder.build()); + String syncStatusText = getSyncStatusText(); + if (!mNotificationContentText.equals(syncStatusText)) { + mNotificationContentText = syncStatusText; + mNotificationBuilder.setContentText(mNotificationContentText); + NotificationManager manager = getSystemService(NotificationManager.class); + manager.notify(SYNC_STATUS_NOTIFICATION_ID, mNotificationBuilder.build()); + } // Send broadcast to MainActivity if exit from the app is needed after node stop. if (exitAppAfterNodeStop()) {