Class DynamicTaskViewModel
java.lang.Object
androidx.lifecycle.ViewModel
androidx.lifecycle.AndroidViewModel
com.pranavpandey.android.dynamic.support.model.DynamicTaskViewModel
- All Implemented Interfaces:
DynamicExecutor
An
AndroidViewModel
to manage the DynamicTask
state.-
Field Summary
Fields inherited from interface com.pranavpandey.android.dynamic.util.concurrent.DynamicExecutor
BACKUP_POOL_SIZE, BACKUP_WORK_QUEUE, CORE_POOL_SIZE, KEEP_ALIVE, KEEP_ALIVE_UNIT, MAXIMUM_POOL_SIZE, NUMBER_OF_CORES, THREAD_FACTORY, WORK_QUEUE
-
Constructor Summary
ConstructorDescriptionDynamicTaskViewModel
(Application application) Constructor to initialize an object of this class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
cancel
(boolean mayInterruptIfRunning) Try to cancel the task managed by this view model.void
execute
(DynamicTask<?, ?, ?> task) Execute the supplied task and manage its state.DynamicTask<?,
?, ?> getTask()
Get the task managed by this view model.boolean
Check whether the task is already running.protected void
Methods inherited from class androidx.lifecycle.AndroidViewModel
getApplication
Methods inherited from class androidx.lifecycle.ViewModel
addCloseable
-
Constructor Details
-
DynamicTaskViewModel
Constructor to initialize an object of this class.- Parameters:
application
- The application associated with this view model.
-
-
Method Details
-
onCleared
protected void onCleared() -
getDefaultExecutor
- Specified by:
getDefaultExecutor
in interfaceDynamicExecutor
-
getTask
Get the task managed by this view model.- Returns:
- The task managed by this view model.
-
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:
-