1

I have a media control notification on the lockscreen, that is a foreground service while playing media, and is demoted to a background service when the media is paused using stopForeground(false):

lockscreen

I have it set up this way so that the user can swipe-dismiss the notification when the media is paused. For this most part, this works fine - however, if you pause the media and leave it idle for a long period of time, pressing play on the above notification results in this behavior:

lockbar2

This code is called when the media is paused:

if (mediaManager == null) {
            mediaManager = MediaManager.getInstance();
        }
        lockView.setImageViewResource(R.id.lock_bar_play, R.drawable.ic_action_play);
        notiView.setImageViewResource(R.id.status_bar_play, R.drawable.ic_action_play);
        startForeground(FOREGROUND_SERVICE, notification);

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        stopForeground(STOP_FOREGROUND_DETACH);
    else
        stopForeground(false);

...and this code is called after pressing play:

if (mediaManager == null) {
            mediaManager = MediaManager.getInstance();
        }
        lockView.setImageViewResource(R.id.lock_bar_play, R.drawable.ic_player_pause);
        notiView.setImageViewResource(R.id.status_bar_play, R.drawable.ic_player_pause);
        startForeground(FOREGROUND_SERVICE, notification);
        Log.i(TAG, "Clicked Play");

Why does it behave this way? The notification exists until I attempt to update the icon, at which point it self destructs and doesn't recreate.

Christian Boler
  • 151
  • 2
  • 17
  • Possible to share your code ? Also, on which OS version it is happening ? – Tasneem Apr 05 '19 at 18:14
  • I am currently testing on API 28 - as for sharing my code, I'm not entirely sure if that's possible at this time. I've seen this question asked before elsewhere on this site, but it went unanswered so I went ahead and posted a new one. I was able to get farther along than what the question asked, but am now experiencing a new issue. See here: https://stackoverflow.com/questions/53502244/how-to-make-notification-dismissible-when-playing-music-in-background-like-in-sp – Christian Boler Apr 05 '19 at 18:18
  • @Tasneem updated my post a bit and added some history in the above comment – Christian Boler Apr 05 '19 at 18:25
  • Possible duplicate of [How to make notification dismissible when playing music in background like in Spotify and Google Music](https://stackoverflow.com/questions/53502244/how-to-make-notification-dismissible-when-playing-music-in-background-like-in-sp) – Christian Boler Apr 15 '19 at 16:12

0 Answers0