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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:02:33+00:00 2026-06-13T07:02:33+00:00

I put a broadcast receiver inside my android service class. So far only one

  • 0

I put a broadcast receiver inside my android service class. So far only one called “receiver”. Is it better to have only one broadcast receiver with a selection statement in it (like if else if)? Can I put more than one broadcast receiver inside an android service class?

For example, this sample code is similar to what I work with. There is an ‘else if’ statement in it to handle two different intent broadcasts:

 public BroadcastReceiver receiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent){
        String action = intent.getAction();
    if(action.equals("com.test.AudioPlay")){
            // action for play
            Toast.makeText(AudioService.this, "play audio from service", Toast.LENGTH_LONG).show();
        }
        else if(action.equals("com.test.AudioPause")){
            // action for pause
            Toast.makeText(AudioService.this, "pause audio from service", Toast.LENGTH_LONG).show();
        }
    }

};
  • 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-13T07:02:35+00:00Added an answer on June 13, 2026 at 7:02 am

    If you will use only one broadcast receiver with different action will be more efficient than different broadcast receivers for all the actions.

    You should bind the service with your activity as I read that you are trying to broadcast for start, pause and all functionality for music player.
    For more info about the boundservices you can refer the developer blog.

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

Sidebar

Related Questions

I have managed to put a broadcast receiver from the manifest file, it looks
I have a broadcast receiver that starts a service when the device is finished
Put value as a field makes sense only if this one represents some object's
If I have an inner class that extends BroadcastReceiver within my Service class, should
Put them all in one separate folder structure or along with classes which implements
I am making a Client Server application for my Android phone. I have created
I have an update service that starts at boot. The thing is I want
In my app I am creating a broadcast receiver which will listen for network
I am working on my first Android's service ever and I want it to
In my Android application, I have a simple list view with adapter. There's a

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.