Fix service not stopping on close video or removed from recents

Stop the `BackgroundMode` service when close icon on player is pressed.

Stop the `BackgroundMode` service when app is removed by user from task manager.
This commit is contained in:
Krunal Patel 2022-11-30 11:02:19 +05:30
parent e1100db58e
commit 93546382b9
2 changed files with 10 additions and 0 deletions

View File

@ -353,6 +353,14 @@ class BackgroundMode : Service() {
}
}
/**
* Stop the service when app is removed from the task manager.
*/
override fun onTaskRemoved(rootIntent: Intent?) {
super.onTaskRemoved(rootIntent)
onDestroy()
}
/**
* destroy the [BackgroundMode] foreground service
*/

View File

@ -303,6 +303,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
mainActivity.supportFragmentManager.beginTransaction()
.remove(this)
.commit()
BackgroundHelper.stopBackgroundPlay(requireContext())
}
playerBinding.closeImageButton.setOnClickListener {
viewModel.isFullscreen.value = false
@ -311,6 +312,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
mainActivity.supportFragmentManager.beginTransaction()
.remove(this)
.commit()
BackgroundHelper.stopBackgroundPlay(requireContext())
}
binding.playImageView.setOnClickListener {