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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:24:41+00:00 2026-05-19T04:24:41+00:00

I have an network application which uses a select loop like this: bool shutdown=false;

  • 0

I have an network application which uses a select loop like this:

bool shutdown=false;
while (!shutdown) {

     [do something]
     select(...,timeout);
}

THe main loop cannot work like this in an Android application anymore since the application needs to receive Intents, need to handle GUI, etc.

I think I have basically three possibilities:

  1. Move the main loop to the java part of the application.
  2. Let the loop run in its own thread and somehow communicate from/to java.
  3. Screw Android <= 2.3 and use a native activity and use AInputQueue/ALooper instead of select.

The first possibility is not easy since java has no select which works on fds. Simply using the select and return after each loop to java is not an elegant possibility either since that requires setting the timeout to something like 20ms to have a good response time in the java part of the program.

The second probability sound nicer but I have do some communication between java and the c++/c part of the program. Things that cold work:

  1. Using a socket, kind of ugly.
  2. using native calls in the “java gui thread” and callback from native in the “c thread”. Both threads need to have thread safe implementations but this is managable.

I have not explored the third possibility but I think that it is not the way to go.

I think I can hack something together which will work but I asking what is the best path to chose.

  • 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-19T04:24:41+00:00Added an answer on May 19, 2026 at 4:24 am

    Based on limited info provided, I can think of following approach:

    A loop can run in a separate thread with two options:
    a) look for gui led changes (based on value of a global native state variable say, native_app_state, of enum type)
    b) something happens that triggers a callback to Java

    You can have separate native functions or one integrated native function to respond to GUI events from Java – where you can use the state of that global native state variable.

    You can optimize the implementation based on what happens in each state, and the performance constraints of the application.

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

Sidebar

Related Questions

I have an application which uses Active Directory intensively. I want to know if
I have a Flash-based (AC3) application which does some network activity. Is there any
I have a small application which sends files over the network to an agent
I have an application which consumes a WCF Service. I have no access to
I have N- Tier application Which consist of three parts: 1. Client (WPF) 2.
I am working on a server application which will have quite a fair number
I am currently involved in developing a low level network application. We have lately
I have a C\C++ code that receives a structure over the network, from this
I have the following requirements: Keeping a list of users on disk for future
I've been searching the net for answers but I can't seem to find a

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.