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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:44:58+00:00 2026-05-30T03:44:58+00:00

I know this is a long post, but please bear with me :) Currently

  • 0

I know this is a long post, but please bear with me 🙂

Currently i’m using the Handler class to communicate from a child thread to the main UI thread, and i’m using my implementation of a message queue for messages in the other direction (from main thread to child thread).

The way the child node knows where to send the messages is: in the main thread, after i create the Handler object, i send it’s reference to the child through my own message queue, the child thread then stores the reference value and thus will know how to send the messages to the activity.

BUT, i have multiple Activities in my application, and each one needs to communicate with the same child thread. The Handler object I create in one Activity won’t be valid in the next Activity, so what I’ve done is every time a new activity is created, (every time the user changes between activities), every time i create a Handler object, exactly the same way as before and send it’s reference to the child thread.

MY QUESTIONS ARE:

Is this a proper way of doing it?
Is there an easier way of doing this? Of communicating from a child node to multiple Activities? Except using for example a singleton class or something, so i don’t send the reference every time through my custom queue but instead update the variable in the singleton.

EDIT

Here is some code, as requested:

In the onCreate method of every Activity i do the following:

...
//Create the main handler on the main thread so it is bound to the main thread's message queue. 
createHandler();

//Send to the controller the msg handler of the UI thread
  //Create messenger of appropriate type
  Messenger mess = new Messenger(_MSGHANDLER_);
  //Add the handler 
  mess.addContent(_HANDLERTAG_, mMainHandler);
  //Add the name of this activity
  mess.addContent(_ACTIVITYNAMETAG_, "RemyLoginActivity"); 
  //Add the message to the controller's queue 
  controller.enqueue(mess)
...

The function createHandler creates the handler object and attaches the specific callback function.

//Create the handler on the main thread so it is bound to the main thread's message queue
private void createHandler()
{
    //Create the main handler on the main thread so it is bound to the main thread's message queue. 
    mMainHandler = new Handler() 
    {
        public void handleMessage(Message msg) 
        {
            //Get the messenger from the message  
            Messenger mess = (Messenger)msg.obj;
            Log.i( "Remy", "ActivityMainMenu::Message from Controller: " + mess.type());

            switch( mess.type() )
            {

                default: Log.i("Remy","OUPS::createHandler::Could not understand queue message type: " + mess.type());
                         break;
            }
        }
    };      
}

and finally , the controller is the child thread in which when it receives the handler reference it just stores it, and then it sends messages like so:

activityHandler.sendMessage( msg );

Hope i haven’t forgotten something.

  • 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-30T03:44:59+00:00Added an answer on May 30, 2026 at 3:44 am

    It sounds like you want to use an IntentService to implement your child thread’s functionality (it already acts like a message queue, to save you reinventing the wheel), and a BroadcastReceiver to allow the child to broadcast its results to any interested party (which in your case will be any of the relevant activities).

    See this tutorial for a good example of using IntentService and BroadcastReceiver in exactly this way.

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

Sidebar

Related Questions

I know this is a long shot - but is there any way at
I know this might be a long shot, but here it goes. I have
I know this one is going to be a long-shot, but I thought I'd
I want to know if this web app are using long polling or anything
This looks like a long shot, but does anyone know of a way to:
I know this might be a no-brainer, but please read on. I also know
This question is a bit long, please bear with me. In REST, i think
First, it is long post so if you need clarification please let me know.
I know the post seems long, but I'm sure there's a very simple solution.
Sorry for the long post, but this forum always asks for use cases :-).

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.