diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java index 4a17fbbda..44b673a4d 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java @@ -172,8 +172,7 @@ public class DownloadService extends Service { setupNotificationUpdaterIfNecessary(); syncExecutor.execute(() -> onDownloadQueued(intent)); } else if (numberOfDownloads.get() == 0) { - stopForeground(true); - stopSelf(); + shutdown(); } else { Log.d(TAG, "onStartCommand: Unknown intent"); } @@ -227,10 +226,6 @@ public class DownloadService extends Service { } unregisterReceiver(cancelDownloadReceiver); - stopForeground(true); - NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - nm.cancel(R.id.notification_downloading); - // if this was the initial gpodder sync, i.e. we just synced the feeds successfully, // it is now time to sync the episode actions SyncService.sync(this); @@ -550,14 +545,7 @@ public class DownloadService extends Service { if (numberOfDownloads.get() <= 0 && DownloadRequester.getInstance().hasNoDownloads()) { Log.d(TAG, "Attempting shutdown"); - stopForeground(true); - stopSelf(); - - // Trick to hide the notification more quickly when the service is stopped - // Without this, the second-last update of the notification stays for 3 seconds after onDestroy returns - notificationUpdater.run(); - NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - nm.cancel(R.id.notification_downloading); + shutdown(); } } @@ -647,4 +635,14 @@ public class DownloadService extends Service { new PostDownloaderTask(downloads), 1, 1, TimeUnit.SECONDS); } } + + private void shutdown() { + // If the service was run for a very short time, the system may delay closing + // the notification. Set the notification text now so that a misleading message + // is not left on the notification. + notificationUpdater.run(); + cancelNotificationUpdater(); + stopForeground(true); + stopSelf(); + } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java index 64ed85cf3..7c8fe9452 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java @@ -53,7 +53,7 @@ public class DownloadServiceNotification { String contentTitle = context.getString(R.string.download_notification_title); String downloadsLeft = (numDownloads > 0) ? context.getResources().getQuantityString(R.plurals.downloads_left, numDownloads, numDownloads) - : context.getString(R.string.downloads_processing); + : context.getString(R.string.service_shutting_down); String bigText = compileNotificationString(downloads); notificationCompatBuilder.setContentTitle(contentTitle); diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index e9c1d8fcd..8e15d60d7 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -270,7 +270,7 @@ %d download left %d downloads left - Processing downloads + Service shutting down Downloading podcast data %d download succeeded, %d failed