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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:45:34+00:00 2026-05-18T08:45:34+00:00

I am getting confused with all the different terminology when using Android: Activity, Service…

  • 0

I am getting confused with all the different terminology when using Android: Activity, Service…

Right now I create a service:

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

And this service starts a thread:

public class RingerServer extends Service {

    public void onCreate() {
        super.onCreate();

        new Thread(new Ringer()).start();
    }

    public class Ringer implements Runnable { ... }

    public void refuseConnection() { ... }

}

In this service, the RingerServer, I also have methods that I want to use. I would like to keep a reference to the RingerServer. I would basically like the Activity that created the service to be able to call refuseConnection(), but not make that method static.

startService returns a ComponentName, so I’ve been trying to cast it back to RingerServer but that doesn’t seem to work. I see that it has getClass() and I’ve checked and getClassName() gives me the correct class. I haven’t been able to use getClass() properly though.

Is there any way I can please keep a reference to the newly created RingerServer class? I am sure this is trivial, but I am stuck right now.

Thank you very much,

James

  • 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-05-18T08:45:35+00:00Added an answer on May 18, 2026 at 8:45 am

    You have two options

    1.Override onStartCommand of the service and start the server with intent using an action. that intent will be received in service, based on the intent action you can call refuseConnection()

    //In Activity 
    ...
    //Start the service 
    Intent intent=new Intent("com.xx.xx.REFUSE_CONNECTION");
    startService(this,intent);
    ...
    //In Service 
    
    public void onStart(Intent intent, int startId) {
            super.onStart(intent, startId);
            if(intent.getAction().equals("com.xx.xx.REFUSE_CONNECTION")){
                //Refuse the connection
                refuseConnection();
            }else {
                //Do something else
            }
    }
    

    //In Manifest

    <service android:name="RingerService">
         <intent-filter>
           <action android:name="com.xx.xx.REFUSE_CONNECTION"></action>
         </intent-filter>
    </service>
    
    1. Implement AIDL interface and override onBind() of service , and use this interface to call refuseConnection(). Refer to this link http://developer.android.com/guide/developing/tools/aidl.html regarding AIDL.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting a bit confused with UIViews recently, I have been using them fine
I'm getting confused with the include/exclude jargon, and my actual SVN client doesn't seem
I'm getting confused by bank switching in PIC assembler... This works for putting a
I'm getting confused re the range of options for development & deploying some simple
I am getting confused between TCP being Connection oriented and UDP being connectionless so
I'm getting confused in the doco how I should be setting up Ninject. I'm
I'm getting confused by pointers in objective-c. Basically I have a bunch of static
I am getting confused with size_t in C. I know that it is returned
A common issue I have is getting confused what $(this) is referring to. I
Im trying to get into some basic JavaFX game development and I'm getting confused

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.