Baseflow / Baseflow/XamarinMediaManager
Notification stays even after swiping app away with app switcher
- Dominant language
- C#
- Stars
- 763
- Forks
- 299
- PR merge metrics
- No merged PRs in 30d
Description
### Device
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.
1. Swipe out the notification
2. by force stopping (killing) the app from installed apps => app => settings in android
3. 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](https://github.com/justcoding121/xamarin-sandbox/blob/main/Xamarin.SandboxApp/Xamarin.SandboxApp/Xamarin.SandboxApp.Android/MainActivity.cs#L36). So, the [MediaBrowserService](https://github.com/Baseflow/XamarinMediaManager/blob/develop/MediaManager/Platforms/Android/MediaSession/MediaBrowserService.cs#L169) 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](https://github.com/justcoding121/xamarin-sandbox) 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.
https://github.com/justcoding121/xamarin-sandbox/blob/main/Xamarin.SandboxApp/Xamarin.SandboxApp/Xamarin.SandboxApp.Android/MainActivity.cs#L26
https://github.com/justcoding121/xamarin-sandbox/blob/main/Xamarin.SandboxApp/Xamarin.SandboxApp/Xamarin.SandboxApp/MainPage.xaml.cs#L19
### Configuration
**Version:** 1.0.8
**Platform:**
- [ ] :iphone: iOS
- [X] :robot: Android
- [ ] :checkered_flag: WPF
- [ ] :earth_americas: UWP
- [ ] :apple: MacOS
- [ ] :tv: tvOS
- [ ] :monkey: Xamarin.Forms
Contributor guide
Assessment
This issue has not been assessed yet.