https://github.com/unfoldingword-dev/android-task-manager
A library for sanely performing threaded tasks that are accessible from the UI thread.
https://github.com/unfoldingword-dev/android-task-manager
Last synced: 2 months ago
JSON representation
A library for sanely performing threaded tasks that are accessible from the UI thread.
- Host: GitHub
- URL: https://github.com/unfoldingword-dev/android-task-manager
- Owner: unfoldingWord-dev
- License: mit
- Created: 2016-06-15T00:15:50.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-03-21T21:14:27.000Z (over 9 years ago)
- Last Synced: 2025-03-13T03:43:57.504Z (over 1 year ago)
- Language: Java
- Size: 103 KB
- Stars: 0
- Watchers: 6
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#Task Manager
A library for sanely performing threaded tasks that are accessible from the UI thread.
The task manager provides a way for an application to perform certain tasks that need to be kept
track of without breaking the ui. When you queue a task you receive a task id (or you can provide your own) that can be used
to check up on the task at a later time, in a different thread, or in a different activity.
##Installation
To use this library your Android project must be configured to use the JCenter or Maven Central repositories.
Add the following to your package dependencies and sync gradle.
```
compile 'org.unfoldingword.tools:task-manager:1.5.0'
```
##Example Usage
Here is a popular way to use the task manager.
This example does not cover storing the task id for later reference.
You could use `onSavedInstanceState` or some other custom method for keeping track of the id.
```
public int connectToTask(String taskId) {
MyManagedTask task = (MyManagedTask) TaskManager.getTask(taskId);
if(task != null) {
// connect to existing task
task.setOnFinishedListener(this);
task.setOnProgressListener(this);
} else {
// start new task
task = new MyManagedTask();
task.setOnFinishedListener(this); // assuming this class implements the listener
task.setOnProgressListener(this); // assuming this class implements the listener
taskId = TaskManager.addTask(task);
}
return taskId;
}
```
##Creating Tasks
You can create your own tasks by excenting the `ManagedTask` class. Or you can create anonymous tasks directly
```
ManagedTask task = new ManagedTask() {
@Override
public void start() {
//... some code
}
};
TaskManager.addTask(task);
```