Class DynamicTaskViewModel

java.lang.Object
androidx.lifecycle.ViewModel
androidx.lifecycle.AndroidViewModel
com.pranavpandey.android.dynamic.support.model.DynamicTaskViewModel
All Implemented Interfaces:
DynamicExecutor

public class DynamicTaskViewModel extends AndroidViewModel implements DynamicExecutor
An AndroidViewModel to manage the DynamicTask state.
  • Constructor Details

    • DynamicTaskViewModel

      public DynamicTaskViewModel(@NonNull Application application)
      Constructor to initialize an object of this class.
      Parameters:
      application - The application associated with this view model.
  • Method Details

    • onCleared

      protected void onCleared()
      Overrides:
      onCleared in class ViewModel
    • getDefaultExecutor

      @NonNull public ExecutorService getDefaultExecutor()
      Specified by:
      getDefaultExecutor in interface DynamicExecutor
    • getTask

      @Nullable public DynamicTask<?,?,?> getTask()
      Get the task managed by this view model.
      Returns:
      The task managed by this view model.
    • execute

      public void execute(@Nullable DynamicTask<?,?,?> task)
      Execute the supplied task and manage its state.
      Parameters:
      task - The task to be executed.
    • isRunning

      public boolean isRunning()
      Check whether the task is already running.
      Returns:
      true if the task is already running.
    • cancel

      public void cancel(boolean mayInterruptIfRunning)
      Try to cancel the task managed by this view model.
      Parameters:
      mayInterruptIfRunning - true if the thread executing the task should be interrupted; otherwise, in-progress tasks are allowed to complete.
      See Also: