private void disconnect() { // All the null checks are necessary because this method is run when an account is added // from out of the app as well try { if (mLoginTask != null) mLoginTask.get(); // Disconnecting in the middle of a login may be troublesome } catch (InterruptedException | ExecutionException e) { Crashlytics.logException(e); } try { if (api != null) { api.disconnect(); api = null; } } catch (SmackException.NotConnectedException e) { Crashlytics.logException(e); } if (mSmackAndroid != null) mSmackAndroid.onDestroy(); isConnected = Boolean.FALSE; }
@Override public void onDestroy() { // Cancel the persistent notification. notificationManager.cancel(JANE_NOTIFICATION_CODE); // disconnect bluetooth proxy try { bt.releaseProxy(); } catch (Exception e) { e.printStackTrace(); } // close smack AsyncTask<Void, Void, Integer> smackShutdown = new AsyncTask<Void, Void, Integer>() { @Override protected Integer doInBackground(Void... params) { connection.disconnect(); return 1; } }; smackShutdown.execute(); smack.onDestroy(); // unregister JaneIntent receiver this.unregisterReceiver(stateIntents); // unregister tts tts.shutdown(); // Tell the user we stopped. Toast.makeText(this, "Jane service stopped.", Toast.LENGTH_SHORT).show(); super.onDestroy(); }
public void onDestroy() { cleanupConnection(); smackAndroid.onDestroy(); }