I have a project that involves using an Android device to send commands to and receive messages from a remote embedded controller (similar to an Arduino) via Bluetooth SPP
.
I have successfully created a single activity app based on a series of tutorials on YouTube. Much of the code in the tutorial is taken from the official BluetoothChat example but it is not done as a service.
Now for my problem... I need to set up a "Home Page" activity that will start other activities when a corresponding button is clicked.
Each activity spawned off the Home Page will have button controls to send commands via Bluetooth to the embedded controller to perform different functions.
The initial Bluetooth connection is started in my Home Page activity. When a new activity is started though, my Home Page's onStop()
method is called and the Bluetooth connection is lost.
Short of duplicating the Bluetooth Code in each activity, it would seem a service is the way to go? I found this post on Stack Overflow link that is very good, but I'm new enough to Android programming that the missing details have made me hit a brick wall.
Also, the example does not address multiple activities using the service. What is the best way for me to approach multiple activities using a Bluetooth connection?