I have the MainActivity thread which contains a Fragment class. The purpose of that fragment is to allow user to connect to a Bluetooth device.
After the user is connected the ConnectedThread starts its while loop which is listening to incoming bytes.
In the MainActivity I have a Boolean value which changes based on whether checkbox is checked or not. I would like to pass that value from the MainActivity to that while loop when it changes.
So the question is, what is the right way to do that? Is there any trick like a handler for that? Or should I pass the context to the ConnectedThread and then set a listener for that in the ConnectedThread class?
Solved
you can use interface as callback here. declare an interface in your MainActivity and have your class with connected thread implement it.
once value changes in MainActivity trigger the callback method and you can pass your variable as a parameter to other class.
Comments
Post a Comment