title: android 4.3 BLE device getting auto disconnect after multiple connection attempts
body: <p>I am developing an app with BLE features for Android and it works perfectly fine, except when I attempt to connect and disconnect the BLE device multiple times. After several successful attempts at connect/disconnect, the BLE device directly calls the disconnect function after random interval of time even though it gets connected first. </p>
  
  <pre><code>public boolean connect(final String address)
  {
  
    if (mBtAdapter == null || address == null) {
         Log.v("Notification", "BluetoothAdapter not initialized or unspecified address.");
         return false;
     }
  
     // Previously connected device.  Try to reconnect.
     //mBtDeviceAddress != null &amp;&amp; address.equals(mBtDeviceAddress)&amp;&amp;
     if (deviceGatt.get(address) != null) {
         Log.v("Notification", "Trying to use an existing mBluetoothGatt for connection.");
         if (deviceGatt.get(address).connect()) {
             mConnectionState = STATE_CONNECTING;
             Log.v("Notification","Connection State :" +mConnectionState);
             return true;
         } else {
             return false;
         }
     }
  
     final BluetoothDevice device = mBtAdapter.getRemoteDevice(address);
     pairedDevice = device;
     if (device == null) {
         Log.v("Notification", "Device not found.  Unable to connect.");
         return false;
     }
     // We want to directly connect to the device, so we are setting the autoConnect
     // parameter to false.
     BluetoothGatt mBluetoothGatt = device.connectGatt(this,false,this.mGattCallBack);
  
     deviceGatt.put(address,mBluetoothGatt);
  
     Log.v("Notification", "Trying to create a new connection.");
     Log.v("Notification","Size of device gatt "+deviceGatt.size());
     mBtDeviceAddress = address;
     mConnectionState = STATE_CONNECTING;
     return true;
  }
  
  public boolean disconnect(BluetoothDevice device) {
  
     if (mBtAdapter == null || deviceGatt.get(device.getAddress()) == null) {
         Log.v("Notification", "BluetoothAdapter not initialized");
         return false;
     }
     //Log.v("Notification","Device Address : "+device.getAddress());
     deviceGatt.get(device.getAddress()).disconnect();
     //deviceGatt.get(device.getAddress()).close();
     return true;
  }
  </code></pre>