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)
:
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:
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.