title: calling connectGatt() and createBond() together
body: <p>I'm trying to create a bond between my Android phone and my device. Before they were connected well by calling <code>device.connectGatt()</code> with my <code>gattCallback</code>. But now as I want to also want to add bonding by calling <code>device.createBond()</code>, my <code>onConnectionStateChange</code> shows an alternate pattern of connected and disconnected with the status code 0 when connected and 8 when disconnected. Here is my snippet of code of how I'm trying to use <code>connectGatt</code> and <code>createBond</code> together.</p>
  <pre><code>    @Override
      public void onScanResult(int callbackType, ScanResult result) {
          System.out.println(&quot;on scan result&quot;);
          super.onScanResult(callbackType, result);
          BluetoothDevice device = result.getDevice();
          synchronized (this) {
              if (mBluetoothGatt == null) {
                  if (device.createBond()) {
                      System.out.println(&quot;create bond success&quot;);
                      mBluetoothGatt = device.connectGatt(mListener.retrieveApplicationContext(), true, mGattCallback);
                  }
                  else System.out.println(&quot;create bond sb&quot;);
              }
          }
      }
  </code></pre>
  <p>Is there anything wrong by calling these two methods in this way? I searched the internet for creating bonds but none of the pages uses createBond and connectGatt together. I only got a hint from this post about how to call these two methods this way: <a href="https://stackoverflow.com/questions/43409638/android-ble-oncharacteristicchanged-using-notify-not-triggered">Android BLE onCharacteristicChanged() using notify not triggered</a></p>
  <p>Also, my <code>BroadCastReceiver</code> always shows device bonding as well but never shows device bonded.</p>