I want to stop a foreground service which extends MediaLibrarySession only after clicking a specific button on the activity, so i tried :
val serviceIntent = Intent(this@PartyHostActivity, PlayerService::class.java)
stopService(serviceIntent)
and
val serviceIntent = Intent(this@PartyHostActivity, PlayerService::class.java)
startService(serviceIntent)
stopService(serviceIntent)
but none of them stops the service, onDestroy
function on the MediaLibraryService was never invoked!!!!why?!!!!
The problem was i had two threads running on the service and i didn't invoke release()
methods for the session
and the player
so stopForeground()
and stopSelf()
didn't work. i tried creating a method to stop and release all and invoked the method on the onStartCommand
method with the action "STOP_SERVICE"
like the answer here and onDestroy()
has been called successfully