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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:55:22+00:00 2026-06-17T03:55:22+00:00

I have a MainActivity which will issue IPC call to a remote AutoCompleteService service.

  • 0

I have a MainActivity which will issue IPC call to a remote AutoCompleteService service.

During execution of AutoCompleteService‘s IPC function, the service will issue another IPC call back to MainActivity.

MainActivity.java

// Receive IPC call from AutoCompleteService.
private StockInfoObserver.Stub stockInfoObserver = new StockInfoObserver.Stub() {

    @Override
    public void update(StockInfo stockInfo) throws RemoteException {
        // TODO Auto-generated method stub
        Log.i(TAG, android.os.Process.myPid() + " : MainActivity receive ipc call : " + Thread.currentThread().getId());
    }

};

...
...
...

// Issue IPC call to AutoCompleteService.
button.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {
        // Test on API.
        try {
            Log.i(TAG, android.os.Process.myPid() + " : MainActivity start issue IPC call to remote service : " + Thread.currentThread().getId());
            // autoCompleteApi.handle will issue IPC call to remote service.
            autoCompleteApi.handle("abc");
            Log.i(TAG, android.os.Process.myPid() + " : MainActivity end issue IPC call to remote service : " + Thread.currentThread().getId());
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

});

AutoCompleteService.java

private AutoCompleteApi.Stub autoCompleteApi = new AutoCompleteApi.Stub() {    
    private List<StockInfoObserver> stockInfoObservers = new ArrayList<StockInfoObserver>();

    @Override
    public void handle(String string) {
        Log.i(TAG, android.os.Process.myPid() + " : AutoCompleteService start receive ipc call : " + Thread.currentThread().getId());
        try {
            for (StockInfoObserver stockInfoObserver : stockInfoObservers) {    
                Log.i(TAG, android.os.Process.myPid() + " : AutoCompleteService start IPC call to MainActivity : " + Thread.currentThread().getId());
                // stockInfoObserver.update will issue IPC call back to MainActivity
                stockInfoObserver.update(null);
                Log.i(TAG, android.os.Process.myPid() + " : AutoCompleteService end IPC call to MainActivity : " + Thread.currentThread().getId());
            }
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Log.i(TAG, android.os.Process.myPid() + " : AutoCompleteService end receive ipc call : " + Thread.currentThread().getId());
    }

    @Override
    public void attachStockInfoObserver(StockInfoObserver stockInfoObserver)
            throws RemoteException {
        if (stockInfoObservers.contains(stockInfoObserver) == false) {
            stockInfoObservers.add(stockInfoObserver);
        }
    }
};

My initial expectation is that, deadlock will occur. This is due to my observation. When issuing an IPC call, the issuer will only return from IPC call, after the IPC receiver finished its IPC function execution.

  1. MainActivity issues IPC call to AutoCompleteService through autoCompleteApi.handle.
  2. MainActivity will now wait till AutoCompleteService finished its execution.
  3. AutoCompleteService issues IPC call to MainActivity through stockInfoObserver.update.
  4. AutoCompleteService will now wait till MainActivity finished its execution.
  5. However, MainActivity‘s thread is still waiting, there are no thread which will perform update function.
  6. Both processes keep waiting for each others.

However, the above doesn’t occur. This is the Log I’m getting. Everything just work flawless.

// Log in MainActivity TAG
3930 : MainActivity start issue IPC call to remote service : 1
3930 : MainActivity receive ipc call : 1
3930 : MainActivity end issue IPC call to remote service : 1

// Log in AutoCompleteService TAG
3961 : AutoCompleteService start receive ipc call : 494
3961 : AutoCompleteService start IPC call to MainActivity : 494
3961 : AutoCompleteService end IPC call to MainActivity : 494
3961 : AutoCompleteService end receive ipc call : 494

But I don’t really understand. If the MainActivity thread (with Id 1) is not returning from a function call (autoCompleteApi.handle), how can it “jump” over to execute another function (update(StockInfo stockInfo))?

I would be expecting MainActivity receive ipc call being printed by different thread. Not the thread with Id 1. If not, deadlock should occur.

In case you are interested to try to out, kindly download the complete source code right here : https://www.dropbox.com/s/8hd7v5acjd213l1/jstock-android2.zip

  • 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-17T03:55:23+00:00Added an answer on June 17, 2026 at 3:55 am

    An interesting question. My first thought that the incoming IPC call is handled on a different thread (as it normally would occur with an incoming IPC call) turned out to be wrong in this specific scenario.

    Looking at the execution stack when the incoming call arrives one sees (most recent stack frames at the top):

    MainActivity$1.update
    MainActivity$1.onTransact
    MainActivity$1.execTransact         <- this gets called by the incoming IPC call
    BinderProxy.transact                <- this is where the outgoing IPC call is made
    AutoCompleteApi$Stub$Proxy.handle
    MainActivity$3.onClick
    ...
    

    So all is taking place in the same thread. The incoming call looks like a subroutine call of the outgoing call. The magic to make this possible is happening in native code (or maybe in the kernel). There is an interesting paper by Thorsten Schreiber explaining some of the internals of the Binder mechanism. Unfortunately it does not the discuss the back call to the same process as it happens in this example.

    There is a small remark about the feature in this blog post:

    Note that the original thread may also receive BR_TRANSACTION commands while it is waiting for a reply. This represents a recursion across processes the receiving thread making a call on to an object back in the original process. It is the responsibility of the driver to keep track of all active transactions, so it can dispatch transactions to the correct thread when recursion happens.

    Maybe there is more to find in the OpenBinder website, the root of the Android Binder implementation.

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

Sidebar

Related Questions

Currently I have a blank service, which will eventually be used to determine if
I have an activity ( MainActivity.java ) in which content view is like this
I have an activity, I'll call it mainactivity for now. And I want to
I have a mainActivity which is Customer.java with listview of 5 diff. activities. I
I have an Activity in which when I press back button then its not
I have a MainActivity the default start up Activity which creates a TCP worker
In my Android project I just have one Activity - MainActivity.java. I added another
I have a created a screen for which it will ask the password and
i have main activity in which i have Four menus. and i have one
I am making an app in which i have a main activity that 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.