title: Stop BLE scan started in runnable
body: <p>I am developing an app in which I will be searching for available beacons in range continuously, when the user displays a certain fragment of the app. In order to do this I created a <code>Runnable</code> in which i call a method which starts a scan. Scan results are send to the <code>Handler</code> using a <code>Message</code>. The problem I have is that I don't know how can I call a method which would stop the scan. My code:</p>
  
  <pre><code>private class BleScanRunnable implements Runnable, BleScanCallback {
  
          private final BleScanCallback mBleScanCallback = this;
          private BleScan mBleScan =
                  BleScanFactory.getFactory(BleFragment.this.getActivity())
                          .createBleScan();
  
          @Override
          public void onScanResult(BluetoothDevice device, int rssi, byte[] scanRecord) {
              Message msg = mHandler.obtainMessage();
              Bundle bundle = new Bundle();
              bundle.putParcelable(ARG_BLUETOOTH_DEVICE, device);
              bundle.putInt(ARG_RSSI, rssi);
              bundle.putByteArray(ARG_SCAN_RECORD, scanRecord);
              msg.setData(bundle);
              mHandler.sendMessage(msg);
          }
  
          @Override
          public void run() {
              mBleScan.startBleScan(mBleScanCallback);
          }
  
      }
  </code></pre>
  
  <p>How I start and stop the runnable:</p>
  
  <pre><code>    private void startBleRunnable() {
          ExecutorService threadPoolExecutor = Executors.newSingleThreadExecutor();
          BleScanRunnable bleScanRunnable = new BleScanRunnable();
          mBleScanRunnableFuture = threadPoolExecutor.submit(bleScanRunnable);
      }
  
      private void stopBleRunnable() {
          mBleScanRunnableFuture.cancel(true);
      }
  </code></pre>
  
  <p>The question is how can I not only stop the Runnable, but also call <code>mBleScan.stopBleScan()</code> method in <code>onPause()</code> method of the <code>BleFragment</code></p>
  
  <p>Is it OK to add such method:</p>
  
  <pre><code>public void stopBleScan() {
      mBleScan.stopBleScan();
  }
  </code></pre>
  
  <p>to the <code>BleScanRunnable</code> and call it from <code>onPause()</code> like this:</p>
  
  <pre><code>mBleScanRunnable.stopBleScan();
  </code></pre>