public void onDestroy() { // savePreferences("myPref"); // savePreferences("preferences"); if (!isRecording) { Log.i(TAG, "in onDestroy"); if (conn != null) { try { conn.stop(); } catch (Exception e) { Log.i(TAG, "Error in socket close: " + e.getMessage()); } } stop = true; super.onDestroy(); } }