연결 부분 소스 입니다.
private class ConnectThread extends Thread { // 소켓 생성 부분
private final BluetoothSocket mmSocket;
private final BluetoothDevice mmDevice;
public ConnectThread(BluetoothDevice device) {
mmDevice = device;
BluetoothSocket tmp = null;
// Get a BluetoothSocket for a connection with the
// given BluetoothDevice
try {
tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
} catch (IOException e) {
Log.e(TAG, "create() failed", e);
}
mmSocket = tmp;
}
private class ConnectedThread extends Thread { // I/O Stream 생성 부분
private final BluetoothSocket mmSocket;
private final InputStream mmInStream;
private final OutputStream mmOutStream;
public ConnectedThread(BluetoothSocket socket) {
Log.d(TAG, "create ConnectedThread");
mmSocket = socket;
InputStream tmpIn = null;
OutputStream tmpOut = null;
// Get the BluetoothSocket input and output streams
try {
tmpIn = socket.getInputStream();
tmpOut = socket.getOutputStream();
} catch (IOException e) {
Log.e(TAG, "temp sockets not created", e);
}
mmInStream = tmpIn;
mmOutStream = tmpOut;
}
그냥 private으로 Socket이나 InputStream, OutputStream을 선언하여 바로 받아오는 것이 아니라,
private final로 선언하고 임시 Socket, InputStream,OutputStream(빨간색 부분)으로 먼저 받아온 후,
다시 넘겨주는 이유가 무엇인지 잘 모르겠습니다;;
아시는 분은 답변 주시면 감사하겠습니다 : )