My guess is that this has something to do with the Thread
itself. When you start your Activity
for the first time, you also call .start()
on the Thread
, that would work fine.
The problem is when you leave your Activity
and open it up again. In that case, one of onStop()
or onPause()
is called (depending on situation), and onRestart()
or onResume()
will be called afterwards respectively.
The trick comes now: Meanwhile all that process, your Thread
is still running. As you show your code, it has not been stopped/paused, and keeps running all the time. So basically my tip is that there's something you do within your onCreate()
method of your Activity
that should also be done in your onPause()
and onStop()
events, and my another tip it's somewhere within your ConnectThread(BluetoothDevice device)
method.
To know how to procceed, I'd firstly define both onStop()
and onPause()
methods within your Activity
and see which is fired, log every attribute to see its value/state, and that way you'll be able to debug what is failing.
There's a diagram of the Activity lifecycle.