title: Android how to read multiple BLE characteristics with a PriorityQueue
body: <p>A bit stuck here, might need your help. I want to read several BLE characteristics at once, some people suggest using PriorityQueue for that. I already know all the uuids, etc. just need a way to read several at once.
  Could anyone explain how exactly should it look like? Or maybe there is yet another easier solution?</p>
  
  <p>Thanks in advance, here is my code:</p>
  
  <pre><code>public static final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
  
      PriorityQueue&lt;BluetoothGattCharacteristic&gt; queue = new PriorityQueue&lt;BluetoothGattCharacteristic&gt;();
  
      // When connection state changes
      @Override
      public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
          if (newState == BluetoothProfile.STATE_CONNECTED) {
              Log.v(TAG, "Connected!");
              gatt.discoverServices();
          }
          if (newState == BluetoothProfile.STATE_DISCONNECTED) {
              Log.v(TAG, "Disconnected...");
  
          }
      }
  
      @Override
      public void onServicesDiscovered(BluetoothGatt gatt, int status) {
  
          List&lt;BluetoothGattService&gt; services = gatt.getServices();
          BluetoothGattService rightService = null;
  
          for (int i = 0; i &lt; services.size(); i++) {
              if (services.get(i).getCharacteristics().size() &gt; 8) {
                  rightService = services.get(i);
              }
          }
  
          List&lt;UUID&gt; uuidsList;
  
          UUID TRANSMISSION_POWER = rightService.getCharacteristics().get(4).getUuid();
          UUID BROADCASTING_INTERVAL = rightService.getCharacteristics().get(6).getUuid();
          UUID BEACON_NAME = rightService.getCharacteristics().get(8).getUuid();
          UUID CONNECTION_MODE = rightService.getCharacteristics().get(9).getUuid();
          //UUID SOFT_REBOOT = rightService.getCharacteristics().get(10).getUuid();
  
          uuidsList = new ArrayList&lt;UUID&gt;();
  
          uuidsList.add(TRANSMISSION_POWER);
          uuidsList.add(BROADCASTING_INTERVAL);
          uuidsList.add(BEACON_NAME);
          uuidsList.add(CONNECTION_MODE);
          //uuidsList.add(SOFT_REBOOT);
  
          queue.add(rightService.getCharacteristic(uuidsList.get(0)));
          queue.add(rightService.getCharacteristic(uuidsList.get(1)));
          queue.add(rightService.getCharacteristic(uuidsList.get(2)));
  
      }
  
      @Override
      public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
  
          Log.v(TAG, "CHARACTERISTIC VALUE___: " + characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0));
          onServicesDiscovered(gatt, 0);
  
      }
  
  };
  </code></pre>
  
  <p>UPDATE:</p>
  
  <p>even after putting them on different threads it still only reacts to one gatt.readCharacteristic(...). like following:</p>
  
  <pre><code>// Gatt Callback
  public static final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
  
      // When connection state changes
      @Override
      public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
          if (newState == BluetoothProfile.STATE_CONNECTED) {
              Log.v(TAG, "Connected!");
              gatt.discoverServices();
          }
          if (newState == BluetoothProfile.STATE_DISCONNECTED) {
              Log.v(TAG, "Disconnected...");
  
          }
      }
  
      @Override
      public void onServicesDiscovered(BluetoothGatt gatt, int status) {
  
  
          List&lt;BluetoothGattService&gt; services = gatt.getServices();
  
          /*
          DISPLAY ALL SERVICES AND CHARACTERISTICS
  
          for (int i = 0; i &lt; services.size(); i++) {
              Log.v(TAG, "SERVICE____: " + services.get(i).getUuid());
  
              for (int k = 0; k &lt; services.get(i).getCharacteristics().size(); k++) {
                  Log.v(TAG, "CHARACTERISTIC____: " + services.get(i).getCharacteristics().get(k).getUuid());
              }
  
          }
          */
  
          BluetoothGattService rightService = null;
  
          for (int i = 0; i &lt; services.size(); i++) {
              if (services.get(i).getCharacteristics().size() &gt; 8) {
                  rightService = services.get(i);
              }
          }
  
          List&lt;UUID&gt; uuidsList;
  
          UUID TRANSMISSION_POWER = rightService.getCharacteristics().get(4).getUuid();
          UUID BROADCASTING_INTERVAL = rightService.getCharacteristics().get(6).getUuid();
          UUID BEACON_NAME = rightService.getCharacteristics().get(8).getUuid();
          UUID CONNECTION_MODE = rightService.getCharacteristics().get(9).getUuid();
          //UUID SOFT_REBOOT = rightService.getCharacteristics().get(10).getUuid();
  
          uuidsList = new ArrayList&lt;UUID&gt;();
  
          uuidsList.add(TRANSMISSION_POWER);
          uuidsList.add(BROADCASTING_INTERVAL);
          uuidsList.add(BEACON_NAME);
          uuidsList.add(CONNECTION_MODE);
          //uuidsList.add(SOFT_REBOOT);
  
  
          class powerThread extends Thread{
  
              UUID uuid;
              BluetoothGatt gatt;
              BluetoothGattService service;
              public powerThread(UUID uuid, BluetoothGatt gatt, BluetoothGattService service) {
                  this.gatt = gatt;
                  this.service = service;
                  this.uuid = uuid;
              }
              @Override
              public void run() {
                  gatt.readCharacteristic(service.getCharacteristic(uuid));
              }
          }
          powerThread pt = new powerThread(TRANSMISSION_POWER, gatt, rightService);
          pt.run();
  
  
          class intervalThread extends Thread{
  
              UUID uuid;
              BluetoothGatt gatt;
              BluetoothGattService service;
              public intervalThread(UUID uuid, BluetoothGatt gatt, BluetoothGattService service) {
                  this.gatt = gatt;
                  this.service = service;
                  this.uuid = uuid;
              }
              @Override
              public void run() {
                  gatt.readCharacteristic(service.getCharacteristic(uuid));
              }
          }
          intervalThread it = new intervalThread(BROADCASTING_INTERVAL, gatt, rightService);
          it.run();
  
  
      }
  
      @Override
      public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
  
          Log.v(TAG, "CHARACTERISTIC VALUE___: " + characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0));
  
      }
  
  };
  </code></pre>