Class DefaultTaskScheduler


  • public class DefaultTaskScheduler
    extends TaskScheduler
    The default implementation of TaskScheduler. It uses a Timer. This is not a reliable way for task scheduling in Android, because Android devices may pause the CPU clock when they go to sleep.
    • Constructor Detail

      • DefaultTaskScheduler

        public DefaultTaskScheduler()
    • Method Detail

      • scheduleTask

        protected void scheduleTask​(Object context,
                                    ScheduledTaskSpec taskSpec)
        Description copied from class: TaskScheduler
        Schedules a task at a specified time. At the due time it should call onTriggerTask(). In Android this method is called on the UI thread.
        Specified by:
        scheduleTask in class TaskScheduler
        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: TaskScheduler
        Cancels the scheduled task with the specified task ID. In Android this method is called on the UI thread.
        Specified by:
        cancelScheduledTask in class TaskScheduler
        Parameters:
        context - the context (only set in Android)
        taskId - the task ID
      • runOnUiThread

        protected void runOnUiThread​(Runnable runnable)
        Description copied from class: TaskScheduler
        Runs code on the UI thread in Android. In standard Java, the code can be run immediately on the calling thread.
        Specified by:
        runOnUiThread in class TaskScheduler
        Parameters:
        runnable - the code to run
      • canRunTaskOnMainThread

        protected boolean canRunTaskOnMainThread()
        Description copied from class: TaskScheduler
        Returns whether isRunOnWorkerThread() 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:
        canRunTaskOnMainThread in class TaskScheduler
        Returns:
        true if a task can be run on the main thread, false otherwise