diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-06-28 09:21:03 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-06-28 09:21:03 -0700 |
commit | a525c940f3e3910c052f9caffa906048bdab14fc (patch) | |
tree | 6cc180f83049a47044c92d0fe1a2a8a03ea2d6f6 /src/github/daneren2005 | |
parent | 44460d426bae0a074fe2dbd5cec79b0c370bf1f2 (diff) | |
download | dsub-a525c940f3e3910c052f9caffa906048bdab14fc.tar.gz dsub-a525c940f3e3910c052f9caffa906048bdab14fc.tar.bz2 dsub-a525c940f3e3910c052f9caffa906048bdab14fc.zip |
Fix for threads in pool exiting
Diffstat (limited to 'src/github/daneren2005')
-rw-r--r-- | src/github/daneren2005/dsub/service/DownloadService.java | 5 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/util/BackgroundTask.java | 17 |
2 files changed, 17 insertions, 5 deletions
diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index 0c5c8e24..0a13e16e 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -29,6 +29,7 @@ import static github.daneren2005.dsub.domain.PlayerState.PREPARING; import static github.daneren2005.dsub.domain.PlayerState.STARTED; import static github.daneren2005.dsub.domain.PlayerState.STOPPED; +import github.daneren2005.dsub.R; import github.daneren2005.dsub.audiofx.AudioEffectsController; import github.daneren2005.dsub.audiofx.EqualizerController; import github.daneren2005.dsub.audiofx.VisualizerController; @@ -45,6 +46,7 @@ import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.MediaRouteManager; import github.daneren2005.dsub.util.ShufflePlayBuffer; import github.daneren2005.dsub.util.SimpleServiceBinder; +import github.daneren2005.dsub.util.SyncUtil; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.util.compat.RemoteControlClientHelper; import github.daneren2005.serverproxy.BufferProxy; @@ -263,9 +265,11 @@ public class DownloadService extends Service { if(bufferTask != null) { bufferTask.cancel(); + bufferTask = null; } if(nextPlayingTask != null) { nextPlayingTask.cancel(); + nextPlayingTask = null; } if(remoteController != null) { remoteController.stop(); @@ -975,6 +979,7 @@ public class DownloadService extends Service { public synchronized void reset() { if (bufferTask != null) { bufferTask.cancel(); + bufferTask = null; } try { // Only set to idle if it's not being killed to start RemoteController diff --git a/src/github/daneren2005/dsub/util/BackgroundTask.java b/src/github/daneren2005/dsub/util/BackgroundTask.java index 63515f19..ad9d89c0 100644 --- a/src/github/daneren2005/dsub/util/BackgroundTask.java +++ b/src/github/daneren2005/dsub/util/BackgroundTask.java @@ -135,13 +135,20 @@ public abstract class BackgroundTask<T> implements ProgressListener { } public void cancel() { - cancelled = true; - if(task != null) { - task.cancel(); + if(cancelled) { + // Already cancelled, don't do anything + return; } - if(cancelListener != null) { - cancelListener.onCancel(); + cancelled = true; + if(task != null && task.isRunning()) { + if(cancelListener != null) { + cancelListener.onCancel(); + } else { + task.cancel(); + } + + task = null; } } public boolean isCancelled() { |