Accessing A Bluetooth "connectedthread" From Various Activities
I have created a BluetoothManager much like the one in this example. This object is instantiated in a connection activity, reached from the main acitivty by clicking on a 'Connect
Solution 1:
First of all, even though a singleton could be a solution, android Service
's are there for this purpose, since these are elements that can keep running when your UI is out. So my suggestion would be to create a sticky service an then you have two options:
- Handle data using a handler between the activity and the
Service
. Maybe if you are not too familiar with theHandler
api this will take some time to you. In this example of the official documentation you can also check how to use the handler. - Create a bound service, to which you can bind from the activities and send some data when required. Here you have the official information about bound services.
You can have a look to this tutorial to get more information about handlers.
Post a Comment for "Accessing A Bluetooth "connectedthread" From Various Activities"