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

  • Home
  • SEARCH
  • 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 8667339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:56:28+00:00 2026-06-12T17:56:28+00:00

I have an application that listens to broadcasts and sends broadcasts. When the application

  • 0

I have an application that listens to broadcasts and sends broadcasts.
When the application sends a broadcast it expects a broadcast back from another application.

I catch the broadcast in my receiver and then send the content to a regular java class called ‘decode’.
Here I check the contents of the broadcast and call a method on the mainActivity to launch another activity.

This mainActivity has no real UI, so I was thinking of making a service to replace it.
So I instead of calling mainActivity from decode, I would make a service and call a method from that service.

Now , since I have no experience with android services, is this a good case to use a service ?
Where can I find a good example of android services?

  • 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-12T17:56:29+00:00Added an answer on June 12, 2026 at 5:56 pm

    You’re right, this is the time to use a Service since you should never call an Activity method from outside the Activity. I will give you the most basic Service as a template, and then you can add stuff to it as you like:

    public class MyService extends Service{
    
        @Override
        public IBinder onBind(Intent intent) {
            // TODO Auto-generated method stub
            return null;
        }
    
        @Override 
        public void onCreate() {
            super.onCreate();
            Log.i("daim", "MyService has started ...");
            startMyMethod();    
        }
    
        @Override
        public void onDestroy() {
            super.onDestroy();
            Log.e("daim", "MyService has stopped ...");    
        }
    
        public void startMyMethod(){
            // do your work
        }
    }
    

    Now in order to start this service, you call the method startService and to stop it, call the method stopService. Now if you want to stop the service inside the service, for example when your work is done. You could call stopSelf(); inside your service method. Google for startService and stopService in order to see what parameters are needed, and how to call them depending if you are inside an Activity or not, this is where you might need the Context if you call it from inside a class.

    http://developer.android.com/reference/android/app/Service.html

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

Sidebar

Related Questions

I have an application that sends broadcast messages and listens for response packets. Below
I have an application that runs (listens to incoming TCP data) from the command
I have an application that listens on a port for information from scripts on
I have an application that listens on a port for UDP datagrams. I use
I have an application that listens to a piece of hardware on a USB
I have a server application that binds to a port and listens on it.
I've written an application in Swing that listens for UDP packets from a smart
I have an application that listens for screen off, and user present intents. Since
I have an application that I'm currently testing that listens for requests over the
I have an application that is running as a background service and constantly listens

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.