@Override public int onStartCommand(final Intent intent, final int flags, final int startId) { String action = null; if (intent != null) action = intent.getAction(); Log.i(DEBUG_TAG, "onStartCommand; action=" + action); if (ACTION_ABORT_TEST.equals(action)) { Log.i(DEBUG_TAG, "ACTION_ABORT_TEST received"); stopTest(); return START_NOT_STICKY; } if (ACTION_START_TEST.equals(action) || ACTION_LOOP_TEST.equals(action)) { if (testTask != null && testTask.isRunning()) { if (ACTION_LOOP_TEST.equals(action)) // do not cancel test if running in loop mode return START_STICKY; testTask.cancel(); // otherwise cancel } completed = false; // lock wifi + power lock(); testTask = new RMBTTask(getApplicationContext()); testTask.setEndTaskListener(this); testTask.execute(handler); Log.d(DEBUG_TAG, "RMBTTest started"); handler.postDelayed(addNotificationRunnable, 200); handler.postDelayed(deadman, DEADMAN_TIME); return START_STICKY; } return START_NOT_STICKY; }