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

The Archive Base Latest Questions

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

I am connecting to a terminal emulator using a library in android, this connects

  • 0

I am connecting to a terminal emulator using a library in android, this connects to a serial device (a switch) and shows me sent/received data.

When I receive data the method below is automatically run. When I receive data I wanted to update the emulator screen using invalidate in the onDataReceived method, however this was not working for some reason and so I created a handler to do it every 1 second instead and that works.

public void onDataReceived(int id, byte[] data) 
{
    dataReceived = new String(data);
    ((MyBAIsWrapper) bis).renew(data);
    mSession.write(dataReceived);

    mSession.notifyUpdate();
    viewHandler.post(updateView);
}

Now I wanted to test the data received for certain characters so I made a for loop in onDataReceived, again this didn’t work, it would only see the character now and again, missing some of them. So I added the loop to the handler instead:

Handler viewHandler = new Handler();
Runnable updateView = new Runnable()
{
    @Override
    public void run() 
 {
        //update screen ever 1000ms
        mEmulatorView.invalidate();

    //should check data received every 1000ms
    for(int i = 0; i < dataReceived.length(); i++)
        {           
            if(dataReceived.charAt(i) == '>')
                {

                     Log.d(TAG, "found >");
                }

            if(dataReceived.charAt(i) == '#')
                {

                     Log.d(TAG, "found #");     
                }
        }
        viewHandler.postDelayed(updateView, 1000);
  }

};

My problem is that while I can see the screen gets updated once per second, in the logs I can see I find the characters much more frequently, it is printing them out to the log 100s of times, why is this?

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

    I don´t really know, but the reason could be, because the runnable is not stopped. Just make an condition that the runnbale should only start if this condition is true. So if it is false, the runnable stops automatically, for example:

            @Override
    public void run() 
     {
        //update screen ever 1000ms
        mEmulatorView.invalidate();
    
         if(yourCondition==true){ //put here a condition that the runnable only starts if this is true
    //should check data received every 1000ms
    for(int i = 0; i < dataReceived.length(); i++)
        {           
            if(dataReceived.charAt(i) == '>')
                {
    
                     Log.d(TAG, "found >");
                }
    
            if(dataReceived.charAt(i) == '#')
                {
    
                     Log.d(TAG, "found #");     
                }
        }
        viewHandler.postDelayed(updateView, 1000);
        }
       }
    
      };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am connecting to a terminal emulator using a library in android, this connects
I am connecting to a terminal emulator using a library in android, this connects
I am connecting to a terminal emulator using a library in android, this connects
I am connecting to a terminal emulator using a library in android, this connects
I am trying to connect to a terminal emulator using a library in android,
Updated question: I am trying to connect to a terminal emulator using a library
We have a terminal emulator (its more then just this, but for the question
I am programming a Windows CE 6 device (Motorola MC3100 scanner Terminal). Using Lazarus
Background To capture data from a logic controller, I'm using screen as a terminal
When connecting to sql server, I have the hardcoded string (local). Is this 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.