views:

68

answers:

0

I am pretty new to Android and very new to Multithreading.

I am writing an android application that contains multiple activities that implement onClickListners which sends a Bluetooth message on button click to . I have successfully been able to connect and keep my BluetoothSocket and OutputStream open while in one activity. I do not do any receiving and will always be connected as a client to a known MAC address. When the user wants to go into a submenu, which is also prompted by a button click, how do I keep my BluetoothSocket open?

I know I will need to have a thread running in the background managing the connection and I will use handlers/messages to exchange data between the BluetoothService thread and the currently active UI thread, but I am not sure what classes and methods I would use to start the BluetoothService thread by the application so that it will accessible by all activities.

Would it be something I start in the first activity of the program and have to implement it in a way that would prevent it from ending onPause() and onStop() and if so how would I start it and what classes would be recommended?

Or is it something I could define in the AndroidManifest.xml file so that it starts and runs at all times once the application is started.

These are just two ideas I had but I know I am probably way off.

Thanks,

Jonathan