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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:43:54+00:00 2026-05-28T04:43:54+00:00

My app is receiving data from a BlueTooth device 4 times a second, parsing

  • 0

My app is receiving data from a BlueTooth device 4 times a second, parsing it and then displaying it to the screen. Everything works fine, until the screen orientation changes, then the textViews revert to their default values set in my onCreate and will not change from there.

I am still receiving the data from my message handler from the bluetooth thread, and the parsing is working fine, but my updateUI() method does nothing. All that is in updateUI() is setting the TextView’s text to the value, like tv_text.setText(doubleValue);. Again, this works fine before the screen gets rotated or sleeps.

Does the View ID change when the screen is rotated so my TextView is the wrong one? How do I get around this? I have seen others with problems of the TextView loosing it’s data, but I’m not sure if that’s the same problem because I am not able to set the text again after rotation.

Thanks.

EDIT: I have discovered some odd behavior.

  1. If I rotate the screen before connecting to the BT device, it will work when I connect. But then it stops when I rotate again.

  2. When I rotate, the text view displays the value that was last assigned to it BEFORE connecting. For example, if do tv.setText(“10”), it will display 10. Then I connect, and it updates with the correct values. Then I rotate, and it does back to displaying 10…

  3. The only time I set the text values in in my updateUI() code and that is called after the message is received and parsed.

Now I’m really confused…

EDIT 2

OK, I did some more testing ans I think I may have located the cause. When I tried to disconnect the bluetooth connection I found out that it wasn’t disconnecting. So then i tried disconnecting before rotating, and then connecting again and it worked.

So I believe that when onCreate is run again, it is duplicating my bluetooth comm thread and ignoring the old one. The problem is I don’t know how to make initialize the BTComm object in a way that it will still work when the activity is destroyed and re created, it is still working and can communicate with the UI. Here is some code:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        if (btc == null){
            btc = new BTComm(this, messageHandler);
        }

        tv_temp1 = (TextView) findViewById(R.id.tv_temp1);
        tv_temp2 = (TextView) findViewById(R.id.tv_temp2);
        tv_temp1Label = (TextView) findViewById(R.id.tv_temp1Label);
        tv_temp2Label = (TextView) findViewById(R.id.tv_temp2Label);
        tv_status = (TextView) findViewById(R.id.tv_status);
    }

and the handler that handles the messages received from the BT comm class (btc)

Handler messageHandler = new Handler() {
         public void handleMessage(Message msg) {
                switch(msg.what){
                case BTComm.MESSAGE_CONNECTED:
                    Toast.makeText(LambdaActivity.this, "Connected!", Toast.LENGTH_SHORT).show();
                    tv_status.setText("Connected.");
                    mode = MODE_CONNECTED;
                    break;
                case BTComm.MESSAGE_READ:
                    parse(msg.getData().getString("results"), msg.getData().getLong("time"));
                    break;
                case BTComm.MESSAGE_DISCONNECTED:
                    Toast.makeText(LambdaActivity.this, "Disconnected!", Toast.LENGTH_SHORT).show();
                    tv_status.setText("Not connected...");
                    mode = MODE_NOT_CONNECTED;
                    break;
                }
         }

    };

It would work if I disconnected and re-connected each time the screen was rotated, but that would interrupt the function of the app’s data logging feature so I don’t want to do that… If I lock the orientation to landscape, the screen obviously doesn’t rotate and cause this problem, but if the phone sleeps, when it wakes up in portrait more, it then rotates to landscape mode and the problem happens.

  • 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-28T04:43:54+00:00Added an answer on May 28, 2026 at 4:43 am

    Just in case anyone else is having this problem I have found a fix.

    I ended up moving my bluetooth listener to a service, and when it receives the data from the BT device, it then broadcasts it and is received by my UI activity.

    Some more information can be found in my other question, here: Android background task and lifecycle

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

Sidebar

Related Questions

I'm receiving byte data from a VNC server, using Real VNC this works in
My webserver is receiving image data from an iOS App via HTTP POST. The
I have an app receiving its data from a database in the assets folder.
I have an iPhone app. that is receiving data with IRFC 3339 timestamp format
i have a design issue regarding sending user data from a mobile phone app
My iPhone app will be receiving an xml feed from a Java web service.
I have a C# console app App1 that reads a row of data from
In my app, i would be receiving audio data over socket in Linear PCM
I'm designing a system which is receiving data from a number of partners in
I'm trying to send and receive binary data sms from my app (sdk 2.1-update

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.