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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:43:59+00:00 2026-05-26T12:43:59+00:00

I have a BluetoothSocket that I am reading data from, using a separate Thread

  • 0

I have a BluetoothSocket that I am reading data from, using a separate Thread process from the GUI. I wrap the InputStream in DataInputStream so I can do use a a readFully(..) to wait for a specified amount of data. I can run this code for about an hour and then the program locks up and when I debug its stuck at the readFully(). I included in my GUI thread BroadcastReceivers to notify me when the bluetooth disconnects. The BroadCastReceivers never get notified. Not sure why the device just stops sending data if that is the case or not eve sure if the Bluetooth SPP gets dropped but the socket is still open so the Bluetooth Disconnect message never happens. Any ideas as to the fix or even why or how to debug why its stuck would be appreciated.

Here is my ReadBlueTooth class…

public class ReadBlueToothData extends Thread {
    private BluetoothSocket btSocket;
    private BluetoothAdapter bta;
    private DataInputStream dinput;

    public ReadBlueToothData(Activity a,String mac) {
       ...init object...
    }

    public void run() {
        // if socket connected otherwise stop
        if (dinput==null) return;

        byte[] byteArray = new byte[3];


        while (!Thread.interrupted()) {

            dinput.readFully(byteArray, 0, 3);

            // DO something ....
        }

        // close out InputStream nicely
        if (dinput!=null) {
            try {
                dinput.close();

            } catch (IOException e) {   }
        }

        if (btSocket != null) {
            try {
                btSocket.close();
            } catch (IOException e) {}
        }
    }
}
  • 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-26T12:44:00+00:00Added an answer on May 26, 2026 at 12:44 pm

    I don’t get this error anymore by doing this gracefully when detecting a Bluetooth disconnect.

    dinput.close();
    readBlueToothData().interrupt();
    btSocket.close();
    //make sure to check for nulls for all these too
    

    and also then do a check by looking at the data coming in and if the buffer doesn’t increase in size then also call disconnect.

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

Sidebar

Related Questions

Have a photography site that I want to prevent image copying from. How can
Have an app that can use tts to read text messages. It can also
Have a flash player that pops out into a separate popup browser window. And
I have an application that receives data in binary form through Bluetooth. I read
I have a bluetooth Handheld printer that I am able to communicate to using
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have you refactored from an ActiveRecord to a DataMapper pattern? What conditions prompted the
Have noticed issue while testing iphone app that if one quickly opens/dismisses a modal
I made an application that is using Android SDK 2.1. This application uses bluetooth

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.