@Override public void onCreate() { super.onCreate(); // get new executor mExecutor = Executors.newScheduledThreadPool(1); // create registration with "ping" as endpoint // if the EID of this device is "dtn://device" then the // address of this app will be "dtn://device/ping" Registration registration = new Registration("ping"); // additionally join a group registration.add(PING_GROUP_EID); registration.add(STREAM_GROUP1_EID); // set current stream group mStreamGroup = STREAM_GROUP1_EID; try { // initialize the connection to the DTN service initialize(registration); Log.d(TAG, "Connection to DTN service established."); } catch (ServiceNotAvailableException e) { // The DTN service has not been found Log.e(TAG, "DTN service unavailable. Is IBR-DTN installed?", e); } catch (SecurityException e) { // The service has not been found Log.e( TAG, "The app has no permission to access the DTN service. It is important to install the DTN service first and then the app.", e); } }
@Override public void onDestroy() { if (mDestroySessionOnExit) mSession.destroy(); if (mStreamJob != null) { mStreamJob.cancel(false); mStreamJob = null; try { mTransmitter.close(); } catch (InterruptedException e) { Log.d(TAG, "interrupted while closing", e); } catch (IOException e) { Log.d(TAG, "error while closing", e); } } // shutdown executor mExecutor.shutdown(); super.onDestroy(); }