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 7919427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:51:42+00:00 2026-06-03T15:51:42+00:00

I’ve created a music service for my application (a music player), and after making

  • 0

I’ve created a music service for my application (a music player), and after making some tests I’m observing a behaviour that’s causing me a headache as I don’t know how to solve it.

For testing purposes, I’ve modified the service so, as soon as it’s started, it plays a specific mp3 file from my sd card. Also, I’ve modified the application so the first activity is started, it starts the service, and then it calls “finish()”.

Ok, so… I launch the application, and the first activity starts, my service starts and plays the music, the activity finishes and the application is closed and… the music is stopped and after some seconds the service is restarted (I’m using the START_STICKY flag, so I suppose that’s normal).

I don’t want the music to be stopped when I close the application, or in another words, I don’t want the service to be stopped (and then restarted because it’s been stopped) when my application is closed.

Right now, to control the music service, I start the service and then I bind to it so I can call the service functions I’ve defined in an interface.

Any ideas?

Thanks!

EDIT:

This is an example of what my application and service do (in the tests I’m doing).

Activity:

public class FirstActivity extends SherlockFragmentActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        startService(new Intent(this, MyService.class));

        ...
        // Here is a postDelayed that will run after 2 seconds and call finish()
    }
}

Service:

public class MyService extends Service {
    private MediaPlayer mPlayer;

    @Override
    public void onCreate() {
        mPlayer = new MusicPlayer(this);
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        // Here is the code that plays the music using MediaPlayer

        return START_STICKY;
    }
}
  • 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-03T15:51:43+00:00Added an answer on June 3, 2026 at 3:51 pm

    do not forget to put that the service is remote in your manifest application tag:

    <service
      android:name="somepackage.PlayerService"
      android:label="Player Service"
      android:process=":remote"/>
    

    Note, that the remote name can be something else, so you can have more than one services that are not bound to the main application process

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I know there's a lot of other questions out there that deal with this

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.