Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8899195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:48:04+00:00 2026-06-15T00:48:04+00:00

In my Android app I want to be able to play some audio in

  • 0

In my Android app I want to be able to play some audio in the background. I figured using a MediaPlayer in a service should be just what I need. So I created a service pretty much following Google’s example code on the Android developer website. However, my problem is that whenever a new activity is started that tries to bind to the service, a new service is started (or at least onCreate is being re-called). I’ve read through the docs and what I’m doing should be completely legal. Can anyone provide some further insight? Thanks!

public class PlayerService extends Service implements MediaPlayer.OnPreparedListener, MediaPlayer.OnErrorListener, MediaPlayer.OnBufferingUpdateListener {

public class PlayerBinder extends Binder {
    PlayerService getService() {
        return PlayerService.this;
    }
}

private final IBinder mBinder = new PlayerBinder();

public IBinder onBind(Intent intent) {
    return mBinder;
}

and from my activity I bind to a service from onCreate

private void doBindService() {
    this.bindService(new Intent(this, PlayerService.class), connection, Context.BIND_AUTO_CREATE);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:48:05+00:00Added an answer on June 15, 2026 at 12:48 am

    When you use bindService your Service is created and tied to the lifecycle of your Activity. That means when your Activity is destroyed, so is your Service.

    If you want your Service to remain started you must first call startService(Intent). You could for example call this in your applications onCreate().

    After that, you can still bind to your Service and when you unbind it will remain started until Android decides to kill your process or if you call stopService(Intent) or stopSelf() from somewhere in your code.

    For better results, and having uninterrupted music playback you should set your Service to run in foreground mode (see this).

    Keep in mind that it will STILL be possible for Android to kill your process and stop the music playback, but if you are in foreground mode the chances are very very slim.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to make an iphone and android app using php.
I'm writing an Android app using Phonegap. I want to be able to press
I am building an android app, and I want to be able to have
I am developing an Android app and want to share some text by opening
I've got an idea for an android app, I want to be able to
I'm creating an app using the andengine for Android. I'm autogenerating some of the
I want to be able to capture altitude in my Android app. I know
I'm working on an Android app where I want users to be able to
I have a song playing continuously in background using an Android MediaPlayer , by
I am developing an android app and I want to know the best way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.