근데 이게 문제가 블루투스에서 보내는 모든 데이터를 받고있어서
GC_FOR_ALLOC freed이 로그캣에 출력이 됩니다.
그래서 데이터를 무식하게 받는게 아니라 0.5초마다라 저장하라고 지정하고 싶은데
어떻게 하면 될까요?
메인 액티비티
final DBHelper dbHelper = new DBHelper(getApplicationContext(), "angle.ab",null,1);
final TextView result = (TextView) findViewById(R.id.text1);
mHandler = new Handler(){ //블루투스 데이터 수신 핸들러
public void handleMessage(Message msg){
if(msg.what == MESSAGE_READ){
try {
readMessage = new String((byte[]) msg.obj, "UTF-8");
if((readMessage.indexOf("s") == 0) && (readMessage.indexOf("e") == 21)) {
if(readMessage != null) { // readmessage와 null(빈값)은 같지 않다
test = readMessage.split("");
str00 = test[0]+test[2]+test[3]+test[4]+test[5]+test[6]+test[7]+test[8]+test[9];
str0 = readMessage.substring(0,22);
str1 = readMessage.substring(1,7); // indexof - 데이터값이 01234 56789 00000 출력될때substring(0,5)일때
str2 = readMessage.substring(8,14); // ex) substring(0,5)이면 01234까지
str3 = readMessage.substring(16,21);
// 모듈에서 넘어오는 데이터에 부호(+,-)값이 포함 되있음
// indexof에 부호값까지 포함함
}
else if(readMessage == null){
readMessage = str0;
}
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
mReadBuffer.setText(str0);
mRead_X.setText(str1); // setText str1값을 mRead_X에 출력
mRead_Y.setText(str2);
mRead_Z.setText(str3);
String readBuffer_X = mRead_X.getText().toString(); // db에 저장
String readBuffer_Y = mRead_Y.getText().toString();
String readBuffer_Z = mRead_Z.getText().toString();
}
if(msg.what == CONNECTING_STATUS){
if(msg.arg1 == 1)
mBluetoothStatus.setText("Connected to Device: " + (String)(msg.obj));
else
mBluetoothStatus.setText("Connection Failed");
}
public void run() {
byte[] buffer = new byte[1024]; // buffer store for the stream 스트림을 위한 버퍼 저장소
int bytes; // bytes returned from read() 읽기()에서 반환된 바이트
// Keep listening to the InputStream until an exception occurs 예외가 발생할 때까지 InputStream을 계속 listening
while (true) {
try {
// Read from the InputStream InputStream에서 읽기
bytes = mmInStream.available();
if(bytes != 0) {
buffer = new byte[1024];
SystemClock.sleep(500);
/*Arrays.fill(buffer, (byte)0x00);
SystemClock.sleep(100);
// pause and wait for rest of data. Adjust this depending on your sending speed.
// 나머지 데이터를 일시 중지하고 기다립니다. 전송 속도에 따라 이 설정을 조정합니다.*/
bytes = mmInStream.available(); // how many bytes are ready to be read?
bytes = mmInStream.read(buffer,0,buffer.length); // record how many bytes we actually read
mHandler.obtainMessage(MESSAGE_READ, bytes, -1, buffer)
.sendToTarget(); // Send the obtained bytes to the UI activity
}
} catch (IOException e) {
e.printStackTrace();
break;
}
}
}
/* Call this from the main activity to send data to the remote device */
public void write(String input) {
byte[] bytes = input.getBytes(); //converts entered String into bytes
try {
mmOutStream.write(bytes);
} catch (IOException e) { }
}
/* Call this from the main activity to shutdown the connection */
public void cancel() {
try {
mmSocket.close();
} catch (IOException e) { }
}
}
}