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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:42:02+00:00 2026-06-02T18:42:02+00:00

I want to write a module that connects to a remote Service. The module

  • 0

I want to write a module that connects to a remote Service.

The module can be used by developers in their apps to connect to a specific (bluetooth-)hardware. It should then connect to a single remoteservice that can be updated seperately in the market.

Because the Remote Service is only allowed to have a single thread for all the apps using it at the same time (Only one connection over bluetooth), I have chosen the messenger approach over AIDL.

My problem is now that I wanted to provide a synchronous method in my public API but the service returns in an handler – and as far as I have understood, the handler will allways wait for the current task to finish… So is there any way to get the answer in a differen thread?

the code of the synchronous method as I would like it to be:

responseDataSync = new Sync<ResponseData>();

    // Send message
    Message msg = Message.obtain(null, Constants.DATA, 1, 0);

    send(msg);

    try {
        ResponseData responseData = responseDataSync.get();

        // with responseDataSync using a countdown latch to synchronize...
// but it never fires thanks to the handler.
//etc...

Thanks in advance. I hope my question was somewhat understandable… 😉

/EDIT:
I want some method that returns data from the server. like

 public ResponseData returnResponse(Data dataToSend)

but I can’t wait for the service’s return because then I am stuck in the thread what blocks the handler from returning…

  • 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-02T18:42:03+00:00Added an answer on June 2, 2026 at 6:42 pm

    A Handler is associated with a single message queue. If you send a Message from any Thread it will get enqueued there.

    The Thread that receives all the Messages will get the appropriate message off the queue and handle it – one by one.

    Meaning for you that if you have a Handler and you run all Messages through you handler you don’t need synchronization since everything is handled in a single thread.

    Edit: to create a Handler that handles messages in a background thread:

    HandlerThread ht = new HandlerThread("threadName");
    ht.start();
    Looper looper = ht.getLooper();
    Handler.Callback callback = new Handler.Callback() {
    
        @Override
        public boolean handleMessage(Message msg) {
            // handled messages are handled in background thread 
            return true;
        }
    };
    Handler handler = new Handler(looper, callback);
    
    handler.sendEmptyMessage(1337);
    

    Edit2: wait on Messages might work like this

    // available for all threads somehow
    final Object waitOnMe = new Object();
    
    HandlerThread ht = new HandlerThread("threadName");
    ht.start();
    Looper looper = ht.getLooper();
    Handler.Callback callback = new Handler.Callback() {
    
        @Override
        public boolean handleMessage(Message msg) {
            // handled messages are handled in background thread
            // then notify about finished message.
            synchronized (waitOnMe) {
                waitOnMe.notifyAll();
            }
            return true;
        }
    };
    Handler handler = new Handler(looper, callback);
    
    // in a different Thread:
    synchronized (waitOnMe) {
        handler.sendEmptyMessage(1337);
        try {
            waitOnMe.wait();
        } catch (InterruptedException e) {
            // we should have gotten our answer now.
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a little Linux Kernel Module that can show me the
I created module for admin specific operations. I don't want to write the same
I want to write a test that calls a remote server and validates the
Basically, I want to write a kernel module that adds a possible filter to
I want to write a Module Arg[f_,n_] that takes a function f (having <=n
I want to write a Linux 2.6 netfilter module , which can check the
I want to write a server that can accept multiple clients in python (twisted).
I want to write a python module that sends data to a draft message
I want to write a drupal module that serves static files, but I want
I write 2 GWT module and compile it. I want locate ***.nocache.js files into

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.