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

The Archive Base Latest Questions

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

Communication between two different processes (a service and an activity) in Android can be

  • 0

Communication between two different processes (a service and an activity) in Android can be managed via Messenger or AIDL: it is sufficient that an activity binds to a service.

However, what happens if this activity has one or more sub-activity?
From the moment when the main activity starts a sub-activity, I would like the communication to be redirected to the sub-activity; similarly, when the sub-activity is destroyed, I would like the communication is redirected back to the main activity, etc..

Example # 1:

  1. MyService <—IPC—> MainActivity
  2. MainActivity launches SubActivity, then MyService <—IPC—> SubActivity
  3. SubActivity is destroyed, then MyService <—IPC—> MainActivity

Example # 2:

  1. MyService <—IPC—> MainActivity
  2. MainActivity launches FirstSubActivity, then MyService <—IPC—> FirstSubActivity
  3. FirstSubActivity launches SecondSubActivity, then MyService <—IPC—> SecondSubActivity
  4. SecondSubActivity is destroyed, then MyService <—IPC—> FirstSubActivity
  5. FirstSubActivity is destroyed, then MyService <—IPC—> MainActivity

How to handle these cases?

  • 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-03T17:06:30+00:00Added an answer on June 3, 2026 at 5:06 pm

    You want to have a single entity that is responsible for binding to the service and holding on to the connection and you need that entity NOT to be an Activity instance. Try this:

    • Create a base class (BaseActivity) that subclasses Activity
    • Derive all your activities from BaseActivity
    • Manage the connection between your application and your service using methods in BaseActivity. BaseActivity will need to have static (class) variables that keep track of the connection to the service and deal with binding to the service and shutting it down when you are done with it.
    • Make sure to use the application context (not the activity context) when binding to the service so that the OS won’t kill the connection to the service when the activity is destroyed.

    In this way you don’t have to worry about creating and tearing down connections between the different activities and your service. There is only ever one connection between your entire application (all the activities) and your service.

    I realize that I haven’t explained all the gory details, but hopefully you get the basic idea.

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

Sidebar

Related Questions

I have a WCF client/service app that relies on secure communication between two machines
I am looking for establishing communication between two android phones over WiFi in the
I've learned that MySQL can compress communication between servers and clients. Compression is used
I have a requirment to have communication between two processes using message queues. One
How do you implement two-way communication between two threads with Handlers in Android? I
Is it possible to establish communication between two different apps which are on the
I'm designing a communication protocol that will be used to communicate between two PC
i'm currently experimenting wpf communication between two views of different modules using prism IEventAggregator.
I wanted to set up a simple data communication between two C# applications, and
What options are there to achieve low-latency communication between two wars running in the

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.