title: RFCOMM_CreateConnection - already opened state:2, RFC state:4, MCB state:5
body: <p>I´m writing an android app that connects to a device through bluetooth using RFCOMM. I use the BluetoothChat example as basis for establishing a connection and everything works perfectly most of the time.   </p>
  
  <p>However, sometimes I cannot reconnect due to a message that the socket is already open:    </p>
  
  <blockquote>
    <p>RFCOMM_CreateConnection - already opened state:2, RFC state:4, MCB
    state:5</p>
  </blockquote>
  
  <p>This tends to happen if I connect to the device, close the app (call onDestroy()), reopen it and try to connect again, which results in the above.</p>
  
  <p>I use this method for connecting in the ConnectThread(ref.BluetoothChat example):  </p>
  
  <pre><code>Method m = device.getClass().getMethod("createRfcommSocket",new Class[] {int.class });
  tmp = (BluetoothSocket) m.invoke(device, Integer.valueOf(1));  
  mmSocket = tmp;
  </code></pre>
  
  <p>The only thing that resolves this problem is turning off/on the Bluetooth of the Android phone.   </p>
  
  <p>This leads me to believe that the socket is not being closed in onDestroy() but still I´m calling on closing all threads as shown in the before mentioned example.<br>
  Any ideas would be appreciated.</p>