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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:44:10+00:00 2026-06-18T11:44:10+00:00

I am new to android, I must write a service (on a different process)

  • 0

I am new to android,
I must write a service (on a different process) to handle my internet communication functions,
I checked a few blogs, and found out that using messengers we can communicate between an activity and a service (on a different process),

My question is here, So far I’m doing something like this:

private Messenger _commandReceiver = new Messenger(new CommandDispatcher());

public IBinder onBind(Intent intent) {
    return _commandReceiver.getBinder();
}

class CommandDispatcher extends Handler {
    public void handleMessage(Message message) {
    int command = data.getInt("command");
    Messenger activityMessenger = (Messenger) data.get("messenger");

    switch (command) {
                case Command.IS_AUTHENTICATED:
        break;
        ...
    }
}
}

But why shouldn’t I send the command variable and activity messenger on the onBind method and handle the whole event there, that way the service messenger can be totally removed and communication code is way simpler,
It would become like this

public IBinder onBind(Intent intent) {

    Bundle data = intent.getExtras();
    int command = data.getInt("command");
    Messenger activityMessenger = (Messenger) data.get("messenger");

    switch (command) {
                case Command.IS_AUTHENTICATED:
        break;
        ...
    }
}

I know it might be very simple question, but I couldn’t find the answer anywhere, So I would be thankful if anyone could help me with it

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

    Extending the Binder class
    If your service is private to your own application and runs in the same process as the client (which is common), you should create your interface by extending the Binder class and returning an instance of it from onBind(). The client receives the Binder and can use it to directly access public methods available in either the Binder implementation or even the Service.

    This is the preferred technique when your service is merely a background worker for your own application. The only reason you would not create your interface this way is because your service is used by other applications or across separate processes.

    Using a Messenger
    If you need your interface to work across different processes, you can create an interface for the service with a Messenger. In this manner, the service defines a Handler that responds to different types of Message objects. This Handler is the basis for a Messenger that can then share an IBinder with the client, allowing the client to send commands to the service using Message objects. Additionally, the client can define a Messenger of its own so the service can send messages back.

    http://developer.android.com/guide/components/bound-services.html

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

Sidebar

Related Questions

I am trying to write a service that runs on phone boot, and must
I'm pretty new to writing Android apps, and I wanted to write a piece
So, I got a new job where I must write a database system, that
When creating a new Android application, Eclipse complains Package name must have at least
I am new in android. I have a list that must be viewed like
The new Android 2.1 SDK (version 7) has a new class called SignalStrength: http://developer.android.com/reference/android/telephony/SignalStrength.html
when i am creating new android project from visual studio 2010 it gives the
i am creating a new android application.i am using the table layout. I have
I just installed the new Android SDK and the ADT 17. After the Installation
I am relatively a new Android developer and I am not able to understand

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.