
If the service ever has been started but is not in the foreground, the service would be terminated without calling onDestroy(). This is because when onStartCommand returns START_STICKY [1], the app takes the responsibility to stop the service. Note that this change interrupts the user journey when paused, because the notification is removed. Apps can implement playback resumption [2] to give the user an option to resume playback after the service has been terminated. [1] https://developer.android.com/reference/android/app/Service#START_STICKY [2] https://developer.android.com/guide/topics/media/media-controls#supporting_playback_resumption Issue: androidx/media#175 #minor-release PiperOrigin-RevId: 492192690 (cherry picked from commit 6a5ac19140253e7e78ea65745914b0746e527058)
Media session demo
This app demonstrates use of media sessions. It's a reference app written in Kotlin, which demonstrates best practices for media apps that want to advertise media sessions.
See the demos README for instructions on how to build and run this demo.