예제 #1
0
 // Begin BT connection thread
 private void beginConnection() {
   Log.i(TAG, "BonitorActivity - beginConnection()");
   int element = getIntent().getIntExtra("DEVICE", -1);
   Log.v(TAG, "BT element = " + element);
   // Begin Bluetooth Connection
   if (connectionThread != null) {
     connectionThread.cancel();
   }
   connectionThread = new ConnectionThread(bt.getElement(element));
   connectionThread.start();
 }
예제 #2
0
  private void cancelThreads() {
    // Cancel any thread attempting to make a connection
    if (mConnectionThread != null) {
      mConnectionThread.cancel();
      mConnectionThread = null;
    }

    // Cancel any thread currently running a connection
    if (mConnectedThread != null) {
      mConnectedThread.cancel();
      mConnectedThread = null;
    }
  }
예제 #3
0
 // Back button pressed
 @Override
 public void onBackPressed() {
   Log.e(TAG, "BonitorActivity - onBackPressed()");
   if (connectionThread != null) {
     connectionThread.cancel();
   }
   if (communicationThread != null) {
     communicationThread.cancel();
   }
   if (fileWriter != null) {
     try {
       fileWriter.close();
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
   finish();
 }
예제 #4
0
 // onDestroy
 @Override
 protected void onDestroy() {
   Log.e(TAG, "BonitorActivity - onDestroy()");
   super.onDestroy();
   if (connectionThread != null) {
     connectionThread.cancel();
   }
   if (communicationThread != null) {
     communicationThread.cancel();
   }
   if (fileWriter != null) {
     try {
       fileWriter.close();
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
   finish();
 }