aboutsummaryrefslogtreecommitdiff
path: root/src/github
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-02-19 19:55:22 -0800
committerScott Jackson <daneren2005@gmail.com>2014-02-19 19:55:22 -0800
commit98fb6d8efbcb150fb7764d45ba2aa8e807583afa (patch)
treea4798d949f8f03a5f532b0c83702cd0b8f2fc1d6 /src/github
parentba2c473182e7a039aa2d6b1de2122de64ae02f97 (diff)
downloaddsub-98fb6d8efbcb150fb7764d45ba2aa8e807583afa.tar.gz
dsub-98fb6d8efbcb150fb7764d45ba2aa8e807583afa.tar.bz2
dsub-98fb6d8efbcb150fb7764d45ba2aa8e807583afa.zip
Fix crash from sync adapter
Diffstat (limited to 'src/github')
-rw-r--r--src/github/daneren2005/dsub/util/BackgroundTask.java43
1 files changed, 27 insertions, 16 deletions
diff --git a/src/github/daneren2005/dsub/util/BackgroundTask.java b/src/github/daneren2005/dsub/util/BackgroundTask.java
index 569f1164..b9fe212f 100644
--- a/src/github/daneren2005/dsub/util/BackgroundTask.java
+++ b/src/github/daneren2005/dsub/util/BackgroundTask.java
@@ -50,7 +50,14 @@ public abstract class BackgroundTask<T> implements ProgressListener {
private static final int DEFAULT_CONCURRENCY = 5;
private static final Collection<Thread> threads = Collections.synchronizedCollection(new ArrayList<Thread>());
protected static final BlockingQueue<BackgroundTask.Task> queue = new LinkedBlockingQueue<BackgroundTask.Task>(10);
- private static final Handler handler = new Handler();
+ private static Handler handler = null;
+ static {
+ try {
+ handler = new Handler();
+ } catch(Exception e) {
+ // Not called from main thread
+ }
+ }
public BackgroundTask(Context context) {
this.context = context;
@@ -153,12 +160,14 @@ public abstract class BackgroundTask<T> implements ProgressListener {
return;
}
- handler.post(new Runnable() {
- @Override
- public void run() {
- onDone(result);
- }
- });
+ if(handler != null) {
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ onDone(result);
+ }
+ });
+ }
} catch(InterruptedException interrupt) {
if(taskStart.get()) {
// Don't exit root thread if task cancelled
@@ -169,16 +178,18 @@ public abstract class BackgroundTask<T> implements ProgressListener {
return;
}
- handler.post(new Runnable() {
- @Override
- public void run() {
- try {
- onError(t);
- } catch(Exception e) {
- // Don't care
+ if(handler != null) {
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ onError(t);
+ } catch(Exception e) {
+ // Don't care
+ }
}
- }
- });
+ });
+ }
}
}