From 7eaa37d97c9201ebb9b8f933d7de0d4d278fbd86 Mon Sep 17 00:00:00 2001 From: Adrian Ulrich Date: Thu, 1 Oct 2015 22:28:50 +0200 Subject: [PATCH] beautify notification updates --- .../android/vanilla/PlaybackService.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/ch/blinkenlights/android/vanilla/PlaybackService.java b/src/ch/blinkenlights/android/vanilla/PlaybackService.java index e9391218..1467f4f6 100644 --- a/src/ch/blinkenlights/android/vanilla/PlaybackService.java +++ b/src/ch/blinkenlights/android/vanilla/PlaybackService.java @@ -566,7 +566,7 @@ public final class PlaybackService extends Service mForceNotificationVisible = false; pause(); stopForeground(true); // sometimes required to clear notification - mNotificationManager.cancel(NOTIFICATION_ID); + updateNotification(); } MediaButtonReceiver.registerMediaButton(this); @@ -978,13 +978,14 @@ public final class PlaybackService extends Service if (mMediaPlayerInitialized) mMediaPlayer.pause(); - if (mNotificationMode == ALWAYS || mForceNotificationVisible) { - stopForeground(false); - if (mCurrentSong != null) - mNotificationManager.notify(NOTIFICATION_ID, createNotification(mCurrentSong, mState)); - } else { - stopForeground(true); - } + // We are switching into background mode. The notification will be removed + // unless we forcefully show it (or the user selected to always show it) + // In both cases we will update the notification to reflect the + // actual playback state (or to hit cancel() as this is required to + // get rid of it if it was created via notify()) + boolean removeNotification = (mForceNotificationVisible == false && mNotificationMode != ALWAYS); + stopForeground(removeNotification); + updateNotification(); // Delay entering deep sleep. This allows the headset // button to continue to function for a short period after