altosdroid: Explicitly disconnect BT on termination or 'disconnect'
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / AltosDroid.java
index 10e735c8cbaa5f5b42748ffc8025579d03d5f93c..273688d8f553573fc4bc3ef43d200a1bd3294c57 100644 (file)
@@ -553,6 +553,13 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
                }
        }
 
+       private void disconnectDevice() {
+               try {
+                       mService.send(Message.obtain(null, TelemetryService.MSG_DISCONNECT, null));
+               } catch (RemoteException e) {
+               }
+       }
+
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
                MenuInflater inflater = getMenuInflater();
@@ -610,9 +617,14 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
                        serverIntent = new Intent(this, DeviceListActivity.class);
                        startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE);
                        return true;
+               case R.id.disconnect:
+                       /* Disconnect the bluetooth device
+                        */
+                       disconnectDevice();
+                       return true;
                case R.id.quit:
                        Log.d(TAG, "R.id.quit");
-                       stopService(new Intent(AltosDroid.this, TelemetryService.class));
+                       disconnectDevice();
                        finish();
                        return true;
                case R.id.select_freq: