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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:35:58+00:00 2026-06-16T00:35:58+00:00

I am trying to connect to a terminal emulator using a library in android,

  • 0

I am trying to connect to a terminal emulator using a library in android, this will connect to a serial device and should show me sent/received data. To attach to a terminal session I need to provide an inputstream to setTermIn(InputStream) and an outputstream to setTermOut(OutputStream).

I initialize and attach some streams like so in onCreate(), these are just initial streams and are not attached to the data I want to be sending/receiving.

private OutputStream bos;
private InputStream bis;

...

byte[] a = new byte[4096];
bis = new ByteArrayInputStream(a);
bos = new ByteArrayOutputStream();
session.setTermIn(bis);
session.setTermOut(bos);
/* Attach the TermSession to the EmulatorView. */
mEmulatorView.attachSession(session);

I now want to assign the streams to data as I send and receive it, but I think I am doing it wrong. In The sendData() method, which I call every time I press enter, I have:

public void sendData(byte[] data)
{
        bos = new ByteArrayOutputStream(data.length);         
}

and in the onReceiveData() method, called every time data is received over serial:

public void onDataReceived(int id, byte[] data)
{
        bis = new ByteArrayInputStream(data);           
}

I am not seeing any data on my terminal screen, but I am sending and receiving it over serial successfully. So my question is, should I be setting the streams every single time I am sending and receiving data or just set them once. Also do I need to attach them to the terminal session again mEmulatorView.attachSession(session) somewhere or should the new streams automatically be sent to the screen?

My theory is that my terminal is attached to the old streams and that is why I can’t see data on the terminal screen. Would this be correct?

I tried to set the new input/output streams in each method just once using a boolean and an if statement, but then I get warning messages in logcat

RuntimeException 'sending message to a Handler on a dead thread'

I’ve edited it to write and rad now based on answered but I notice that the library has it’s own write method to feed data to the terminal, so I don’t even know what the streams are for if that is that case, and I need this write to write to the emulator?

public void write(byte[] data,
              int offset,
              int count)
Write data to the terminal output. The written data will be consumed by the emulation     client as input.
write itself runs on the main thread. The default implementation writes the data into a     circular buffer and signals the writer thread to copy it from there to the OutputStream.

Subclasses may override this method to modify the output before writing it to the  stream, but implementations in derived classes should call through to this method to do the  actual writing.

Parameters:
data - An array of bytes to write to the terminal.
offset - The offset into the array at which the data starts.
count - The number of bytes to be written.
  • 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-16T00:35:59+00:00Added an answer on June 16, 2026 at 12:35 am

    Objects in java are passed by reference, hence if you do

    bos = new ByteArrayOutputStream(data.length)
    

    You’re essentially throwing away the previous outputstream and creating a new one.

    Try keeping reference to your input and output stream and write data into it, eg:

    bos.write(data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to connect to a terminal emulator using a library in android,
Iam trying to connect my android device with a bluetooth compatible device. I know
I am trying to run Hierarchy Viewer. developer.android.com says to Connect your device or
I am trying to connect to a MySQL Server using JDBC tool in java
I am trying to connect the JSF to database. This are the files web.xml
I'm trying to connect to a FTP using Apaches FTPSClient but I keep getting
I'm trying to connect java to a Oracle database within terminal. I'm not very
I'm using HostMonster as my web host and I'm trying connect to a database
I'm trying to connect to my localhost MySQL server via php in the terminal.
I am using Paramiko and trying to connect to my SFTP server. Here is

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.