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.
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."
I checked the log and there is no crash point. the following error shown
"01-29 16:57:11.372: A/libc(8684): Fatal signal 11 (SIGSEGV) at 0x00000008 (code=1), thread 8775 (Thread-327)"
`, followed by a very long debug stack trace.
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.
<!---- code -->
@Override
public void onDestroy() {
super.onDestroy();
// Stop the Bluetooth chat services
if (mChatService != null) mChatService.stop();
if(D) Log.e(TAG, "--- ON DESTROY ---");
}
In BluetoothChatService.java, this is the code for stop().
/**
* 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);
}
This does not occur for Android 4.2.1 (Galaxy Nexus) and Android 4.3 (Samsung S4).
Any idea how to fix this? If it is a Android bug, is there any workaround for it?
Many thanks in advance.