I have my first Activity in which the BT connection is established. There is an option presented to the user and, based on their selection, a different Activity will load.>
Have you tried using the Application object to store the Bluetooth connection in an object and using your Activities to get it?
Try something like this. (Note: I have never worked with Bluetooth on Android, so I don't know which relevant classes to use. In this case, I'll use BluetoothDevice
, since it seems to be the right class based on the library documentation)
public class MyApplication extends Application {
BluetoothDevice device;
...
public synchronized BluetoothDevice getBtConnection() {
if (device == null) {
// construct a BluetoothDevice object and put it into variable device
}
return device;
}
}
That way, your first activity just has to do this:
public class FirstActivity extends Activity {
private BluetoothDevice device;
...
@Override
protected void onCreate(Bundle b) {
super(b);
...
device = ((MyApplication) getApplication()).getBtDevice();
...
}
...
}
And then, any time your other Activities need to use that connection, they just need to call getBtDevice()
, because FirstActivity
already instantiated it.