title: BluetoothChat app crashes upon onDestroy() in Android 4.4
body: <p>I have developed a Bluetooth application which communicates with a serial port device and so far the communication (starting the connection, data exchange and terminating the thread) works fine.</p>
  
  <p>However, I encountered a strange problem with Bluetooth connection while testing on Nexus 4 (Android 4.4.2). When I exit the app with a back button, onDestroy() fires as per normal but the app crashes with an error message "Unfortunately,  has stopped."</p>
  
  <p>I checked the log and there is no crash point. the following error shown</p>
  
  <blockquote>
    <p>"01-29 16:57:11.372: A/libc(8684): Fatal signal 11 (SIGSEGV) at
    0x00000008 (code=1), thread 8775 (Thread-327)"</p>
  </blockquote>
  
  <p>`, followed by a very long debug stack trace.</p>
  
  <p>I tried to use the sample Bluetooth app from Android developer website to test whether it is my own implementation issue, and the same crashing issue happens.</p>
  
  <pre><code>&lt;!---- code --&gt;
  @Override
  public void onDestroy() {
  super.onDestroy();
  // Stop the Bluetooth chat services
  if (mChatService != null) mChatService.stop();
  if(D) Log.e(TAG, "--- ON DESTROY ---");
  }
  </code></pre>
  
  <p>In BluetoothChatService.java, this is the code for stop().</p>
  
  <pre><code>/**
   * Stop all threads
   */
  public synchronized void stop() {
      if (D) Log.d(TAG, "stop");
  
      if (mConnectThread != null) {
          mConnectThread.cancel();
          mConnectThread = null;
      }
  
      if (mConnectedThread != null) {
          mConnectedThread.cancel();
          mConnectedThread = null;
      }
  
      if (mSecureAcceptThread != null) {
          mSecureAcceptThread.cancel();
          mSecureAcceptThread = null;
      }
  
      if (mInsecureAcceptThread != null) {
          mInsecureAcceptThread.cancel();
          mInsecureAcceptThread = null;
      }
      setState(STATE_NONE);
  }
  </code></pre>
  
  
  
  <p>This does not occur for Android 4.2.1 (Galaxy Nexus) and Android 4.3 (Samsung S4). </p>
  
  <p>Any idea how to fix this? If it is a Android bug, is there any workaround for it?</p>
  
  <p>Many thanks in advance.</p>