Interface ScheduledTask

    • Method Detail

      • getId

        String getId()
        Returns the task ID. This is set by the TaskScheduler when the task is scheduled.
        Returns:
        the task ID
      • setId

        void setId​(String id)
        Sets the task ID. This is set by the TaskScheduler when the task is scheduled.
        Parameters:
        id - the task ID
      • getName

        String getName()
        Returns the name of this task. This is used for logging. It could be the simple name of the task class.
        Returns:
        the name
      • getTaskData

        String getTaskData()
        Returns the task data that is needed to build a copy of this task instance. It could be a JSON string and it could also be null. See the discussion at TaskScheduler for the cases when this data string is used.
        Returns:
        the task data
      • setTaskData

        void setTaskData​(String taskData)
                  throws ParseException
        The TaskScheduler may call this method when it needs to build a copy of an instance that was passed earlier. In that case it will construct an instance with the default constructor and then call this method. The specified data string was obtained from getTaskData(). It could be a JSON string and it could also be null. See the discussion at TaskScheduler for the cases when this is used.
        Parameters:
        taskData - the task data
        Throws:
        ParseException - if the data string can't be parsed
      • getSchedule

        TaskSchedule getSchedule()
        Returns the schedule at which the task should be run.
        Returns:
        the schedule at which the task should be run
      • run

        void run​(Object context,
                 String taskId,
                 org.joda.time.DateTime now,
                 ScheduleParams scheduleParams)
          throws TaskException
        Runs the task. This method is called by the TaskScheduler at the scheduled times according to the schedule returned by getSchedule(). With repeating tasks this method is called sequentially. If isRunOnWorkerThread() returns true, it will run on a worker thread. Otherwise it will run on the scheduling thread (the UI thread in Android).
        Parameters:
        context - the context (only set in Android)
        taskId - the task ID
        now - the current time
        scheduleParams - the scheduled time parameters
        Throws:
        TaskException - if an error occurs that should be logged
      • isRunOnWorkerThread

        boolean isRunOnWorkerThread()
        Returns whether the task should run on a worker thread or on the UI thread in Android. In standard Java this is ignored and a task is always run on a worker thread.
        Returns:
        true if the task should run on a worker thread, false if it should run on the UI thread
      • cancel

        void cancel​(Object context)
        Cancels the task. This is called by the TaskScheduler if the task was started and should be cancelled. In Android this method is called on the UI thread.
        Parameters:
        context - the context (only set in Android)