InfinitePeriodicalTask () { myUpdateAlarm.addRequest(new Runnable() { @Override public void run() { myUpdateAlarm.addRequest(this, delay); LongRunningReadTask task = taskProvider.compute(); boolean invalidRequest = !task.init(); //noinspection unchecked if (task.shouldStart(currentTask)) { currentTask = task; currentTask.run(); } else if (invalidRequest) { currentTask = null; } } }, delay); return this; }