// 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(); }
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; } }
// 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(); }
// 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(); }