这是我的代码片段。
public void run(){
尝试{
bluetoothServerSocket = BluetoothAdapter。 getDefaultAdapter()。listenUsingRfcommWithServiceRecord(LISTEN_NAME,LISTEN_UUID);
/ *此处阻止线程传入连接* /
bluetoothSocket = bluetoothServerSocket.accept();
...
} catch(Exception e){} finally {
尝试{bluetoothServerSocket.close();} catch(Exception ex){}
尝试{bluetoothSocket.close();} catch(Exception ex){}
}
}
在活动中。
public void onStop(){
尝试{thread.bluetoothSocket.close();} catch(Exception ex){}
尝试{thread.bluetoothServerSocket.close();} catch(Exception ex){}
super.onStop();
}
当我点击后退按钮时。该活动已经结束,但大约一秒后该应用程序退出而没有任何警告。
我的android os版本是2.2。 HTC Desire设备。
答案 0 :(得分:1)
我们应该关闭这样的蓝牙连接:
尝试{synchronized(bluetoothServerSocket){bluetoothServerSocket.close();}} catch(Exception ex){}