@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(MyAction.SERVICE_STATE.getAction())) { MyContextHolder.initialize(context, this); synchronized (mServiceState) { stateQueuedTime = System.nanoTime(); waitingForServiceState = false; mServiceState = MyServiceState.load(intent.getStringExtra(IntentExtra.SERVICE_STATE.key)); } MyLog.d(this, "Notification received: Service state=" + mServiceState); } else if ("android.intent.action.BOOT_COMPLETED".equals(action)) { MyLog.d(this, "Trying to start service on boot"); sendCommand(CommandData.getEmpty()); } else if ("android.intent.action.ACTION_SHUTDOWN".equals(action)) { // We need this to persist unsaved data in the service MyLog.d(this, "Stopping service on Shutdown"); setServiceUnavailable(); stopService(); } }