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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:03:19+00:00 2026-06-17T11:03:19+00:00

on a broadcast I want to call a non static method from Service XYZ.

  • 0

on a broadcast I want to call a non static method from Service XYZ. The Service is start by the receiver on boot.
Has someone a idea to run methods from this running service?
One solution in this forum is to make the method static and use a singleton pattern to execute. But is there another method? Maybe with a binder?

//EDIT for example i have the following clases:

public class MyService extends Service{
   .....
   public void method(){
      //TODO
   }
}
public class MyBroadcastReceiver extends BroadcastReceiver{
   .....
  public void onReceive(Context context, Intent intent) {
    String intentAction=intent.getAction();
    if(intentAction.equals(Intent.ACTION_BOOT_COMPLETED)){  
        //start service
        Intent serviceIntent = new Intent(context, MyService.class);
        context.startService(serviceIntent);

    }
    else{ 
     //TODO call method() in MyService
    }
}

how can i call the method method()? I know that i can cast with context.getSystemService() system services. But how can i get my own service object?

greetings

  • 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-17T11:03:21+00:00Added an answer on June 17, 2026 at 11:03 am

    You can add an action string to your intent using setAction in the intent that launches the Service. In your service’s onStartcommand you can extract the intent’s action, and based off that you can execute the method in your service.

    You will always send commands to your service using startService this will not launch your service twice. It will either get started once, or the new intent is sent to the service.

    So, in your on boot completed section you should set the intent action to whatever you want, and start the service – you can remove the else block completely.

    In your Service implement the onStartCommand, extract the intent’s action, and based off that action you can just execute your method.

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

Sidebar

Related Questions

I have a broadcast receiver which receive an internet state changes. I want to
I am having a receiver that broadcast when a intent service finishes a server
I want to send a broadcast (or is it an intent?) from my app
I want to broadcast simple short message from Android device to iOS and Android
I want to simply call one function that is defined in BroadClass Activity from
I am stuck in this problem . I want to call the method of
I cant access my SQlite database from my broadcast receiver . Is it even
What I want to achieve is to give user a button saying 'Start broadcast
I have an application that is launched from a broadcast receiver, but I don't
In my app,i want to use Shared Preferences inside a broadcast receiver...But i cant

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.