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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:38:50+00:00 2026-06-14T11:38:50+00:00

I use Gingerbread. I already talk to a native serial port (RS-232 native UART,

  • 0

I use Gingerbread. I already talk to a native serial port (RS-232 native UART, not USB dungle). This is done through java.io and a small piece of native code written in C to open and close the stream and configure the baudrate. It works but my first thought was that it is not efficient because I need to setup a thread that constantly poll the inputstream to check if there are bytes coming from the serial port. What a wasteful way to use CPU and batteries.

    private InputStream mInputStream;
private ReadThread mReadThread;

private class ReadThread extends Thread {

    @Override
    public void run() {
        super.run();
        while(!isInterrupted()) {
            int size;
            try {
                byte[] buffer = new byte[64];
                if (mInputStream == null) return;
                size = mInputStream.read(buffer);
                if (size > 0) {
                    onDataReceived(buffer, size);
                }
            } catch (IOException e) {
                e.printStackTrace();
                return;
            }
        }
    }
}

What I Thought I needed to do is to have the same kind of signal as for other events in android where I can setup some kind of listener that would allow me to be informed of some bytes coming and wake up my thread that will take care of the incoming data. I did not find anything like that in the APIs.

But, after looking and researching more, finally, I think this is not wasteful but I’d like an opinion from someone who knows about how threads work in Android. Let’s look at codes lines.

size = mInputStream.read(buffer);

is actually a blocking read. I looked how the device was opened and it is done in C through a NDK/JNI interface and it is open without the flag “NOBLOCK/NODELAY”. Therefor, it should not spin constantly in the while loop but just get blocked on the mInputStream.read and the Kernel should just switch to another thread until there is some data available to read. In such case, this code would be totally fine. Is this assumption true?

I’d like to know that because my embedded system main purpose is to display videos most of the time and I don’t want what I manage behind the scene to suck-up to much resources and give some hiccups in the video playback.

  • 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-14T11:38:51+00:00Added an answer on June 14, 2026 at 11:38 am

    After writing the application, and testing, I can say that the last assumption made in the question is actually true. If the device is open without the flag “NOBLOCK/NODELAY”, the thread will be suspended on the mInputStream.read() until there is data available. No wasteful polling.

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

Sidebar

Related Questions

I want to give android application/service access to native serial port (UART RS-232). When
I'm trying to use Sensor.TYPE_LINEAR_ACCELERATION. Accrording to documentation, starting since level 9 (gingerbread) this
Use case: I find a piece of code that I do not understand at
This is my code for AES. Under Gingerbread I get following error after encrypting
I'm not sure if anyone else noticed it, but the Gingerbread emulator runs like
use DBI(); What is causing this insert to fail to err 1, the SELECT
Anyone experiencing a problem with their app in Gingerbread? -- if you use requestWindowFeature(Window.FEATURE_NO_TITLE);
Use Case Show a photo uploaded by the user in a square box with
use C#,want to upload excel file on google doc. bellow syntax use to upload
use Text::Table; my $tb = Text::Table->new(Planet,Radius\nkm,Density\ng/cm^3); $tb->load( [ Mercury,2360,3.7], [ Mercury,2360,3.7], [ Mercury,2360,3.7], );

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.