altosdroid: Deal with bluetooth connection failures better
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / AltosDroid.java
index 273688d8f553573fc4bc3ef43d200a1bd3294c57..4e7bdd6b331dc7b2d3bd10274d6f75e00f81aef0 100644 (file)
@@ -352,7 +352,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
                for (AltosDroidTab mTab : mTabs)
                        mTab.update_ui(state, from_receiver, location, mTab == mTabsAdapter.currentItem());
 
-               if (state != null)
+               if (state != null && mAltosVoice != null)
                        mAltosVoice.tell(state, from_receiver);
 
                saved_state = state;
@@ -465,8 +465,6 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
                mStateLayout   = (RelativeLayout) findViewById(R.id.state_container);
                mStateView     = (TextView) findViewById(R.id.state_value);
                mAgeView       = (TextView) findViewById(R.id.age_value);
-
-               mAltosVoice = new AltosVoice(this);
        }
 
        @Override
@@ -484,6 +482,8 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
 
                doBindService();
 
+               if (mAltosVoice == null)
+                       mAltosVoice = new AltosVoice(this);
        }
 
        @Override
@@ -504,6 +504,10 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
                if(D) Log.e(TAG, "-- ON STOP --");
 
                doUnbindService();
+               if (mAltosVoice != null) {
+                       mAltosVoice.stop();
+                       mAltosVoice = null;
+               }
        }
 
        @Override
@@ -546,10 +550,12 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
                        String address = data.getExtras().getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS);
                        String name = data.getExtras().getString(DeviceListActivity.EXTRA_DEVICE_NAME);
 
-                       if (D) Log.d(TAG, "Connecting to " + address + name);
+                       if (D) Log.d(TAG, "Connecting to " + address + " " + name);
                        DeviceAddress   a = new DeviceAddress(address, name);
                        mService.send(Message.obtain(null, TelemetryService.MSG_CONNECT, a));
+                       if (D) Log.d(TAG, "Sent connecting message");
                } catch (RemoteException e) {
+                       if (D) Log.e(TAG, "connect device message failed");
                }
        }