AdvancedAndroid_ClassicalMusicQuiz icon indicating copy to clipboard operation
AdvancedAndroid_ClassicalMusicQuiz copied to clipboard

notification does not show when expected

Open fullmers opened this issue 7 years ago • 2 comments

Instead, the notification shows up after you have paused it, presumably because showNotification() is placed in onPlayerStateChanged().

Then the notification disappears after completing a question. It will only reappear after pressing pause again in the next question. This behaviour probably occurs because the activity is finished and recreated with each next question.

Not sure where showNotification() should be placed instead to address these issues.

fullmers avatar Feb 02 '18 11:02 fullmers

Did you find a fix for this? I can't seem to see notification when playing or paused .

Keep Coding : - )

ghost avatar May 12 '18 10:05 ghost

I call showMediaNotification() after mMediaSession.setPlaybackState() inside initMediaSession() to fix this.

But this is not the only problem with notifications. Notification re-appears after cancelled when returning to main activity, because mNotificationManager.cancelAll() must be called AFTER stopPlayer() completes. Otherwise we cancel notification, then call player.stop and this causes state change along with new notification.

Additionally, I had to call initMediaSession() from within initializePlayer() jsut BEFORE mPlayer.addListener() because sometimes callback was called when no mMediaSession or mStateBuilder was created causing crash.

gshadows avatar May 30 '18 17:05 gshadows