Android Question Background Music Not Stopping

Discussion in 'Android Questions' started by Mohamed Akbarally, Jun 14, 2015.

  1. Mohamed Akbarally

    Mohamed Akbarally Member Licensed User

    Hi, I'm running some background music through a service, but the only problem is that when the app is exited(running in completely in the background) the music continues to play. Is there a way to kill the music when there are no activities visible?
     
  2. NJDude

    NJDude Expert Licensed User

    Stop the service in Activity_Pause.
     
    thedesolatesoul likes this.
  3. Mohamed Akbarally

    Mohamed Akbarally Member Licensed User

    i have more than one activity and i dont want the music to stop when the second activity is open?
     
  4. NJDude

    NJDude Expert Licensed User

    Then on the Main activity capture the BACK key and ask if the user wants to exit the app, if yes, then kill the service as it exits.
     
    thedesolatesoul likes this.
  5. Mohamed Akbarally

    Mohamed Akbarally Member Licensed User

    ya but if they click the "home" button instead of the back key doesn't the music continue to play?
     
  6. NJDude

    NJDude Expert Licensed User

    Ok here's the deal, services run in the background, so, you will have to find a way to stop them, in this case, by exiting the app (like I explained previously), the HOME key cannot be captured but it will pause the app, so in conclusion, you can only stop the music playing IF the user EXITS the app.
     
    thedesolatesoul likes this.
  7. Mohamed Akbarally

    Mohamed Akbarally Member Licensed User

    OK then forget services, is there any possible way to implement background music into an application that runs seamlessly across multiple activities, and closes at exit? there must be some way, how do other apps do it?
     
  8. NJDude

    NJDude Expert Licensed User

    You have to use a service.
     
    thedesolatesoul likes this.
Loading...