@Override
  public void onDestroy() {
    if (audioRemoteScanController != null) {
      audioRemoteScanController.closeScanController();
      audioRemoteScanController = null;
    }
    if (remoteReleaseHandle != null) {
      remoteReleaseHandle.close();
      remoteReleaseHandle = null;
    }

    super.onDestroy();
  }
  private void handleReset() {
    // Release the old access if it exists
    if (remoteReleaseHandle != null) {
      remoteReleaseHandle.close();
      remoteReleaseHandle = null;
    }
    if (audioRemoteScanController != null) {
      audioRemoteScanController.closeScanController();
      audioRemoteScanController = null;
    }

    EnumSet<ControlsMode> requestModes = EnumSet.of(ControlsMode.AUDIO_MODE);
    // int desiredDeviceNumber = 4545;
    // AntPlusAudioRemoteControlPcc.requestAccessByDeviceNumber(requestModes, this,
    // desiredDeviceNumber, 0, IPluginAccessResultReceiver, IDeviceStateChangeReceiver);

    // Async scan
    audioRemoteScanController =
        AntPlusAudioRemoteControlPcc.requestRemoteControlAsyncScanController(
            requestModes,
            this,
            0,
            new IRemoteControlAsyncScanResultReceiver() {

              @Override
              public void onSearchStopped(RequestAccessResult reasonStopped) {
                // The triggers calling this function use the same codes and require the same
                // actions as those received by the standard access result receiver
                IPluginAccessResultReceiver.onResultReceived(null, reasonStopped, DeviceState.DEAD);
              }

              @Override
              public void onSearchResult(final RemoteControlAsyncScanResultDeviceInfo deviceFound) {
                for (RemoteControlAsyncScanResultDeviceInfo i : mScannedDeviceInfos) {
                  // The current implementation of the async scan will reset it's ignore list every
                  // 30s,
                  // So we have to handle checking for duplicates in our list if we run longer than
                  // that
                  if (i.resultInfo.getAntDeviceNumber()
                      == deviceFound.resultInfo.getAntDeviceNumber()) {
                    // Found already connected device, ignore
                    return;
                  }
                }

                // We split up devices already connected to the plugin from un-connected devices to
                // make this information more visible to the user,
                // since the user most likely wants to be aware of which device they are already
                // using in another app
                if (deviceFound.resultInfo.isAlreadyConnected()) {
                  mAlreadyConnectedDeviceInfos.add(deviceFound);
                  runOnUiThread(
                      new Runnable() {
                        @Override
                        public void run() {
                          if (adapter_connDevNameList
                              .isEmpty()) // connected device category is invisible unless there are
                          // some present
                          {
                            findViewById(R.id.listView_AlreadyConnectedDevices)
                                .setVisibility(View.VISIBLE);
                            findViewById(R.id.textView_AlreadyConnectedTitle)
                                .setVisibility(View.VISIBLE);
                          }
                          adapter_connDevNameList.add(
                              deviceFound.resultInfo.getDeviceDisplayName());
                          adapter_connDevNameList.notifyDataSetChanged();
                        }
                      });
                } else {
                  mScannedDeviceInfos.add(deviceFound);
                  runOnUiThread(
                      new Runnable() {
                        @Override
                        public void run() {
                          adapter_devNameList.add(deviceFound.resultInfo.getDeviceDisplayName());
                          adapter_devNameList.notifyDataSetChanged();
                        }
                      });
                }
              }
            });
    initScanDisplay();
  }