Notification stays even after swiping app away with app switcher
See original GitHub issueDevice
Samsung S10+ running Android 11
🐛 Bug Report
Thanks for this great work.
The notification won’t go away when CrossMediaManager.Current.Stop();
is called. The song stops, but the notification stays with play icon as shown on screenshot below. Even after the app is swiped away with android task switcher, the notification stays. The only way to make the notification go away is as follows.
- Swipe out the notification
- by force stopping (killing) the app from installed apps => app => settings in android
- by restarting the device.
Ironically, clicking the play icon on the orphaned notification restarts the song again from the first song of the playlist and it works as if the app was relaunched. Not sure if this is a new normal behaviors for Android 11. I started to have this issue since Android update.
I also tried to remove the notification manually by using NotificationManager.ClearAll()
but don’t have any effect.
I noted that the media browser service never stops after Stop()
call as asserted in this line. So, the MediaBrowserService implementation never gets to hit its OnDestroy
block in this case. As a result the foreground notification stays along with the foreground media browser service.
I tried to debug the issue spending most of the time today, but its beyond me.
Expected behavior
The notification should disappear as soon as Stop()
is called or when app is swiped out.
Reproduction steps
Please find sample repository here to reproduce this issue. The repository is just a basic single page Xamarin.Forms app created with visual studio 2019.
Relevant code added to the default blank app is in below two lines, result is shown in screenshot above.
Configuration
Version: 1.0.8
Platform:
- 📱 iOS
- 🤖 Android
- 🏁 WPF
- 🌎 UWP
- 🍎 MacOS
- 📺 tvOS
- 🐒 Xamarin.Forms
Issue Analytics
- State:
- Created 2 years ago
- Comments:7
Hi, I had the same problem, I suggest you do the following:
In your MainActivity when MediaManager starts, catch the MediaManager state change event to ensure that when the player stops it removes the notification.
Yes. You can take the code from this repository and include in your project with few changes.
Everything inside Platform folder will go to individual platform (Android, iOS, UWP) startup project. Remaining code can be put inside a shared .net standard 2.0/2.1 class library project. You will need to make few changes in the CrossMediaManager class , so that the correct MediaManagerImplementation is provided based on the platform. Make sure you have all the platform specific Nuget dependencies in your csproj files.
If you follow the code in official google media player example app (UAMP), specifically its media browser service implementation, you should be good for Android 11 (you may ignore cast feature, which I use, but you probably don’t need). Android 11 has Playback resume feature as documented in developer website.