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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:46:20+00:00 2026-06-10T23:46:20+00:00

I know that the code in onStartCommand will run on the main thread. Inside

  • 0

I know that the code in onStartCommand will run on the main thread.
Inside this method I spawn a new network thread, that communicates with a server and when it finishes it executes a call back method that also runs in the main thread.

My question is, if both methods onStartCommand and the callback method are executed in the main thread, and the call back method is executed whenever the network call finishes, is it possible that lines of code of the call back method are executed in the middle of the execution of the onStartCommand method?

How does this work?

  • 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-10T23:46:21+00:00Added an answer on June 10, 2026 at 11:46 pm

    If the spawned network thread makes a function call that you are certain will execute in the main thread, then the only way to achieve this is by some sort of shared resource, the most common being: some sort of work queue, a socket, or a variable shared between the two threads (set via a method call) that would have to be polled by the main thread causing it to execute a certain method.

    I would think the easiest way would be a work-queue, but according to the link you posted in your comments, it mentions JSON which typically uses a TCP/IP socket. I’ll cover how each method typically works.

    Work Queue:

    The network thread will create some sort of work entry and enqueue it on the main thread work queue. If the main thread is in the middle of a method (onStartCommand()) then it cant also execute the work entry. Most likely when it finishes the current method it will return and get back to a polling method that pulls entries off the queue. So if this approach is used, then onSuccess() and onFailure() will create and enqueue work entries that will be executed after returning from onStartCommand()

    JSON Socket:

    This approach is very similar to the Work Queue, but instead of work entries, socket messages will be used. And there will be a function that will poll (most likely via select() or poll()) the socket and treat the received messages as work items. So if this approach is used, then onSuccess() and onFailure() will create and send socket messages that will be executed after returning from onStartCommand()

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

Sidebar

Related Questions

I know that this line of code will make the cell text-wrap: $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setWrapText(true); 'D1'
i know that there isn't code inside my question, but i think this is
I know that GUI code in Java Swing must be put inside SwingUtilities.invokeAndWait or
I know that PHP is compiled to byte code before it is run on
In code: //I know that to get this effect (being able to use it
I know that Code-First uses conventions for model binding, and that this is the
As I know, GWT needs that code that will be used on client side
I know that c++ code should be compiled and linked by g++, not gcc.
I have code that uses jquery.slideup and jquery.slidedown How can i know that div
I know that the following code should show and hide a tiny circular progress

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.