Package eu.woolplatform.utils.schedule
Class DefaultTaskScheduler
- java.lang.Object
-
- eu.woolplatform.utils.schedule.TaskScheduler
-
- eu.woolplatform.utils.schedule.DefaultTaskScheduler
-
public class DefaultTaskScheduler extends TaskScheduler
The default implementation ofTaskScheduler. It uses aTimer. This is not a reliable way for task scheduling in Android, because Android devices may pause the CPU clock when they go to sleep.
-
-
Field Summary
-
Fields inherited from class eu.woolplatform.utils.schedule.TaskScheduler
LOGTAG
-
-
Constructor Summary
Constructors Constructor Description DefaultTaskScheduler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcancelScheduledTask(Object context, String taskId)Cancels the scheduled task with the specified task ID.protected booleancanRunTaskOnMainThread()Returns whetherisRunOnWorkerThread()should be checked to see if a task should be run on the main thread or on the worker thread.protected voidrunOnUiThread(Runnable runnable)Runs code on the UI thread in Android.protected voidscheduleTask(Object context, ScheduledTaskSpec taskSpec)Schedules a task at a specified time.-
Methods inherited from class eu.woolplatform.utils.schedule.TaskScheduler
cancelTask, cancelTasksWithClass, findTasksWithClass, generateTaskId, initScheduledTasks, onTriggerTask, scheduleTask
-
-
-
-
Method Detail
-
scheduleTask
protected void scheduleTask(Object context, ScheduledTaskSpec taskSpec)
Description copied from class:TaskSchedulerSchedules a task at a specified time. At the due time it should callonTriggerTask(). In Android this method is called on the UI thread.- Specified by:
scheduleTaskin classTaskScheduler- Parameters:
context- the context (only set in Android)taskSpec- the specification of the task instance
-
cancelScheduledTask
protected void cancelScheduledTask(Object context, String taskId)
Description copied from class:TaskSchedulerCancels the scheduled task with the specified task ID. In Android this method is called on the UI thread.- Specified by:
cancelScheduledTaskin classTaskScheduler- Parameters:
context- the context (only set in Android)taskId- the task ID
-
runOnUiThread
protected void runOnUiThread(Runnable runnable)
Description copied from class:TaskSchedulerRuns code on the UI thread in Android. In standard Java, the code can be run immediately on the calling thread.- Specified by:
runOnUiThreadin classTaskScheduler- Parameters:
runnable- the code to run
-
canRunTaskOnMainThread
protected boolean canRunTaskOnMainThread()
Description copied from class:TaskSchedulerReturns whetherisRunOnWorkerThread()should be checked to see if a task should be run on the main thread or on the worker thread. This is used in Android to run tasks on the UI thread. If this method returns false, a task is always run on a worker thread.- Specified by:
canRunTaskOnMainThreadin classTaskScheduler- Returns:
- true if a task can be run on the main thread, false otherwise
-
-