Interface ProgressWorker.Handler

All Known Subinterfaces:
ProgressWorker.ProgressHandler<V>, ProgressWorker.ProgressResultTaskHandler<T,V>, ProgressWorker.ProgressTaskHandler<V>, ProgressWorker.ResultTaskHandler<T>, ProgressWorker.TaskHandler
All Known Implementing Classes:
DomainGeneratorModel.PopulateTask
Enclosing class:
ProgressWorker<T,V>

public static interface ProgressWorker.Handler

Provides default handler methods for the ProgressWorker lifecycle.

All handler methods are called on the UI thread.

Combined with a task interface (via ProgressWorker.TaskHandler, ProgressWorker.ResultTaskHandler, etc.), this allows a single class to encapsulate both the background task and its handlers. Handler methods from this interface are automatically wired when the task is passed to ProgressWorker.BuilderFactory.task(Task), and called first. Any handlers added via the ProgressWorker.Builder are called after, in the order they were added.

See Also:
  • Method Details

    • onStarted

      default void onStarted()
      Called on the UI thread before the background task executes.
    • onDone

      default void onDone()
      Called on the UI thread when the task is done, successfully or not, before the result is processed.
    • onSuccess

      default void onSuccess()
      Called on the UI thread after a successful task execution, before ProgressWorker.ResultTaskHandler.onResult(Object) or ProgressWorker.ProgressResultTaskHandler.onResult(Object) for result-producing tasks.
    • onException

      default void onException(Exception exception)
      Called on the UI thread if an exception occurred during the background task.

      The default implementation rethrows the exception as a RuntimeException. Override to handle the exception, for example by displaying it.

      Parameters:
      exception - the exception
    • onCancelled

      default void onCancelled()
      Called on the UI thread if the background task was cancelled.
    • onInterrupted

      default void onInterrupted()
      Called on the UI thread if the background task was interrupted.

      The default implementation simply calls Thread.currentThread().interrupt().