	public int onStartCommand(Intent intent, int flags, int startId) {
        if (Log.isLoggable(TAG, Log.DEBUG)) Log.d(TAG, "Received start id " + startId + ": " + intent);
        if (intent == null) return START_NOT_STICKY;
        String action = intent.getAction();
        if (action == null) return START_NOT_STICKY;
        if (Log.isLoggable(TAG, Log.DEBUG)) Log.d(TAG, "Action: " + action);
        final int stopId = startId;
        if (action.equals(ACTION_STARTUP))
        {
			Notification n = buildNotification(R.drawable.ic_notification, getResources().getString(R.string.service_running));
    		startForeground(1, n);
    		_executor.execute(new Runnable() {
    	        public void run() {
    	    		if (DaemonManager.getInstance().start(DaemonService.this) )
    	    		{
        	    		invoke_state_changed_intent();
        	    		updateNeighborNotification();
    	    		}
    	    		else
    	    		{
        	    		invoke_state_changed_intent();
        	    		updateNeighborNotification();
        	    		stopSelfResult(stopId);
    	    		}
    	        }
    		});
            return START_STICKY;
        }
        else if (action.equals(ACTION_SHUTDOWN))
        {
        	_executor.execute(new Runnable() {
    	        public void run() {
    	    		DaemonManager.getInstance().stop();
    	    		invoke_state_changed_intent();
    	        	stopForeground(true);
    	    		NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
    	    		nm.cancel(1);
    	    		stopSelfResult(stopId);
    	        }
    		});
            return START_STICKY;
        }
		else if (intent.getAction().equals(de.tubs.ibr.dtn.Intent.REGISTER))
		{
			final Registration reg = (Registration)intent.getParcelableExtra("registration");
			final PendingIntent pi = (PendingIntent)intent.getParcelableExtra("app");
        	_executor.execute(new Runnable() {
    	        public void run() {
    	        	DaemonManager.getInstance().getSessionManager().register(DaemonService.this, pi.getTargetPackage(), reg);
    	        	if (!DaemonManager.getInstance().isRunning()) {
	    	    		stopSelfResult(stopId);
    	        	}
    	        }
    		});
            return START_STICKY;
		}
		else if (intent.getAction().equals(de.tubs.ibr.dtn.Intent.UNREGISTER))
		{
			final PendingIntent pi = (PendingIntent)intent.getParcelableExtra("app");
        	_executor.execute(new Runnable() {
    	        public void run() {
    	        	DaemonManager.getInstance().getSessionManager().unregister(DaemonService.this, pi.getTargetPackage());
    	        	if (!DaemonManager.getInstance().isRunning()) {
	    	    		stopSelfResult(stopId);
    	        	}
    	        }
    		});
            return START_STICKY;
		}
		return START_NOT_STICKY;
	}

	public int onStartCommand(Intent intent, int flags, int startId) {
        if (Log.isLoggable(TAG, Log.DEBUG)) Log.d(TAG, "Received start id " + startId + ": " + intent);
        if (intent == null) return START_NOT_STICKY;
        String action = intent.getAction();
        if (action == null) return START_NOT_STICKY;
        if (Log.isLoggable(TAG, Log.DEBUG)) Log.d(TAG, "Action: " + action);
        final int stopId = startId;
        if (action.equals(ACTION_STARTUP))
        {
			Notification n = buildNotification(R.drawable.ic_notification, getResources().getString(R.string.notify_no_neighbors));
    		startForeground(1, n);
    		_executor.execute(new Runnable() {
    	        public void run() {
    	    		if (DaemonManager.getInstance().start(DaemonService.this) )
    	    		{
        	    		invoke_state_changed_intent();
        	    		updateNeighborNotification();
    	    		}
    	    		else
    	    		{
        	    		invoke_state_changed_intent();
        	    		updateNeighborNotification();
        	    		stopSelfResult(stopId);
    	    		}
    	        }
    		});
            return START_STICKY;
        }
        else if (action.equals(ACTION_SHUTDOWN))
        {
        	_executor.execute(new Runnable() {
    	        public void run() {
    	    		DaemonManager.getInstance().stop();
    	    		invoke_state_changed_intent();
    	        	stopForeground(true);
    	    		NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
    	    		nm.cancel(1);
    	    		stopSelfResult(stopId);
    	        }
    		});
            return START_STICKY;
        }
		else if (intent.getAction().equals(de.tubs.ibr.dtn.Intent.REGISTER))
		{
			final Registration reg = (Registration)intent.getParcelableExtra("registration");
			final PendingIntent pi = (PendingIntent)intent.getParcelableExtra("app");
        	_executor.execute(new Runnable() {
    	        public void run() {
    	        	DaemonManager.getInstance().getSessionManager().register(DaemonService.this, pi.getTargetPackage(), reg);
    	        	if (!DaemonManager.getInstance().isRunning()) {
	    	    		stopSelfResult(stopId);
    	        	}
    	        }
    		});
            return START_STICKY;
		}
		else if (intent.getAction().equals(de.tubs.ibr.dtn.Intent.UNREGISTER))
		{
			final PendingIntent pi = (PendingIntent)intent.getParcelableExtra("app");
        	_executor.execute(new Runnable() {
    	        public void run() {
    	        	DaemonManager.getInstance().getSessionManager().unregister(DaemonService.this, pi.getTargetPackage());
    	        	if (!DaemonManager.getInstance().isRunning()) {
	    	    		stopSelfResult(stopId);
    	        	}
    	        }
    		});
            return START_STICKY;
		}
		return START_NOT_STICKY;
	}
