블루투스 채팅 샘플 소스 입니다.
연결해서 데이터까지 받는데요.. 다음 Activity로 넘어갈때 넘어간 Activity에서 데이터를 계속 받고 싶습니다.
현재 두번째 액티비티도 아래와 같은 소스라서요.. 전혀 감이 잡히지 않네요.. 능력자의 도움을 받고 싶습니다.
일단 상황은
연결해서 데이터 받는 도중에 두번째 액티비티로 넘어가면 state가 초기화가 됩니다..
연결완료가 3번인데 state3을 두번째 Activity에서도 이어서 받아왔으면 합니다.
구지 소스는 아니더라도 조언이라도 부탁드립니다...
// 어플리케이션 시작 시 불린다.
@Override
public void onStart() {
super.onStart();
if (!btAdapter.isEnabled()) {
Intent enableIntent = new Intent(
BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent,RQ_ENABLE_BT);
} else {
if (spp == null)
spp = new SerialService(this, handler);
}
Log.i("Main", "@@ onStart=" + spp.getState());
}
// 어플리케이션 재개 시 불린다.
@Override
public synchronized void onResume() {
super.onResume();
if (spp != null) {
if (spp.getState() == SerialService.STATE_NONE) {
// Bluetooth의 접속 대기(서버)
spp.start();
}
}
Log.i("Main", "@@ onResume=" + spp.getState());
}
// 어플리케이션 파괴 시 불린다.
@Override
public void onDestroy() {
super.onDestroy();
Log.i("Main", "@@ onDestroy");
if (spp!=null) spp.stop();
}
// 채팅 서버로부터 정보를 취득하는 핸들러
private final Handler handler = new Handler() {
// 핸들 메시지
@Override
public void handleMessage(Message msg) {
service = new BluetoothService();
switch (msg.what) {
// 상태 변경
case MSG_STATE_CHANGE:
switch (msg.arg1) {
case SerialService.STATE_CONNECTED:
service.addText("접속 완료", handler, txtGodun) ;break;
case SerialService.STATE_CONNECTING:
service.addText("접속 중", handler, txtGodun) ;break;
case SerialService.STATE_LISTEN:
service.addText("대기중", handler, txtGodun) ;break;
case SerialService.STATE_NONE:
service.addText("미접속", handler, txtGodun) ;break;
}
break;
// 메시지 수신
case MSG_READ:
byte[] readBuf=(byte[]) msg.obj;
service.addText(new String(readBuf, 0, msg.arg1), handler, txtGodun);
break;
case MESSAGE_DEVICE_NAME:
mConnectedDeviceName = msg.getData().getString(SerialService.DEVICE_NAME);
Toast.makeText(getApplicationContext(), mConnectedDeviceName + "에 연결 되었습니다.", Toast.LENGTH_SHORT).show();
break;
case MESSAGE_TOAST:
Toast.makeText(getApplicationContext(), msg.getData().getString(SerialService.TOAST), Toast.LENGTH_SHORT).show();
break;
case MESSAGE_CONNECTING:
Toast.makeText(getApplicationContext(), msg.getData().getString(SerialService.TOAST), Toast.LENGTH_SHORT).show();
break;
}
}
};



