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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:11:34+00:00 2026-06-13T03:11:34+00:00

I have a service called AudioService that extends android class Service. In addition I

  • 0

I have a service called AudioService that extends android class Service. In addition I have 5 activities in my app. How can I bind my one Service to 3 of those Activities only?

What I am interested in is the ability to run the service while the user is viewing any of those three activities, but if they view anything else then the service is shut down.

For example, if the user clicks a button and goes into one of those 3 activities and the service is started. A Mediaplayer object can be started at that time. They can click other navigation buttons or the back button, and as long as they are viewing one of those 3 activities the music keeps on playing without interruption.

  • 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-13T03:11:35+00:00Added an answer on June 13, 2026 at 3:11 am

    Use a shared atomic variable to communicate state with the service. That will allow it to stop / start playing the music.

    1. Declare a static AtomicBoolean on the service and a static method that can set / get the value of this boolean. This should track if the music is already playing. If set to true, the music is playing.

    2. When the user clicks on a button that takes them to an activity, use the onStart() method of that activity to check the value of this boolean. If it is false then the music is not playing. Set it to true. The method that sets it to true should also start playing the music.

    3. On the other 2 activities’s onStart() method, set the value of the AtomicBoolean to false. The method on the service should now set the AtomicBoolean to false and release the mediaplayer.

    The background service itself can keep running. Just rebuild the mediaplayer when you want to start the music again.

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

Sidebar

Related Questions

I have a WCF Service (called myservice.svc) that takes a message from a user
I have a nettcpbinding wcf service.It called 100000+ times in one second so there
I have a Toast that is called from inside a Service . It always
I Have an internal SOAP Web service that is being called from an external
I have a test where I'm mocking 2 service calls that get called in
I have two Services called TemplateService, TemplateReportService (both defined in one WCF Service Library)
I put a broadcast receiver inside my android service class. So far only one
I have a class library called (service.cs). I have WCF service both are in
I have a class called Sound.java that consists of 3 functions (initSound, addSound, and
If I have a service (service-layer object not web service) called WidgetProcessor and that

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.