Android Service Example – Playing Music in Background

Android

Video is ready, Click Here to View ×


In this Android Service Example we will see a very simple example to understand how to create and implement a service in Android.

A service is used for long running background tasks that doesn’t need user interaction.

For the source code and more details visit this link.

Android Service Example for Background Processes

Video is ready, Click Here to View ×

For more tutorials visit
https://www.simplifiedcoding.net

39 thoughts on “Android Service Example – Playing Music in Background

  1. 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.

  2. 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.

  3. 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?

  4. 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 ???

  5. i have made an music player app which plays song which are on the Sd Card i want it to playback like any other music app and stop playing when the app is totally closed what i need to Do!

  6. 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!

    Any ideas? Thanks!

  7. hi sir
    i have developed on music app using service but when i open multiple app my music is stop and i get error when i check my service is running but it was not playing music please help me in this

  8. On the one hand a good explanation but on the other hand definitely the worst capture I have ever seen on YouTube. For the rest I hope you spend it more effort. God damn…. my poor ears.

Leave a Reply

Your email address will not be published. Required fields are marked *