I have observed that the service is restarting when the app is closed.Is there a way to make it run continuously?I don't want my song to stop and start playing from the beginning when I close the app...Any response is appreciated.

Hello sir hope you will be fine… i want an android app in which user can enable lock screen and then set the password for the lock screen and when the person unlock their mobile phone it need a password which he set in our app and a custom image on lock screen how can i do this i search alot but can't find any solution… if you helped me it's very urgent.

how are you not getting any null pointer exception error after closing your application in background?because there is no oncreate override method to initialize the mediaplayer object.and another doubt is how come the media player restarting once the app is completely closed from background?

I want to create an android app which should fetch data from a WEB-API after equal intervals of time (lets say after every five minutes) even if my app is closed. Also it should generate the notifications if new data is fetched.

What is the correct way to do it ??

Do I need to you background service and call a thread from onStartCommand and fetch data in that thread with some sleep time ???

I got the code to work, the service runs in the background while the app is open or when I have another app up, or the home screen (I can even turn off the phone screen and the music will still play, which is cool!)

However, when I swipe away the app (or press the x), the music stops playing and an error pops up: "ServiceExample has stopped". The service does not still run as it did in your example!