I am using a Service
class to play music in the background. While I am displaying the notification bar on top, there is issue in my app. When I kill the app, the mu
According to: https://developer.android.com/reference/android/app/Service.html Change
START_STICKY
to
START_NOT_STICKY
EDIT:
The issue with music stopping for a while is connected with the fact that you run app and service in the same process. And 'killing app' means stopping the whole process bound to it. What you need to do is to run your service in seperate process:
Start a service in a separate process android
That tutorial shows you how to build a BACKGROUND service, which can get killed by the system. To play music you should use a FOREGROUND service.
https://developer.android.com/guide/components/services.html#Foreground
Use onTaskRemoved on your main activity and release your mediaplayer on this event.