summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java26
1 files changed, 12 insertions, 14 deletions
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();
+ }
}