From 6904ea23a693f1ba066503b4cff245a332cdcf11 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Tue, 25 Sep 2012 14:12:59 +0200 Subject: [PATCH] cancel chapter loader thread if service receives shutdown notification --- src/de/danoeh/antennapod/service/PlaybackService.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/de/danoeh/antennapod/service/PlaybackService.java b/src/de/danoeh/antennapod/service/PlaybackService.java index 9b5a404f6..38ee2cf83 100644 --- a/src/de/danoeh/antennapod/service/PlaybackService.java +++ b/src/de/danoeh/antennapod/service/PlaybackService.java @@ -134,6 +134,8 @@ public class PlaybackService extends Service { private SleepTimer sleepTimer; private Future sleepTimerFuture; + + private Thread chapterLoader; private static final int SCHED_EX_POOL_SIZE = 3; private ScheduledThreadPoolExecutor schedExecutor; @@ -556,7 +558,10 @@ public class PlaybackService extends Service { } if (shouldStream && media.getItem().getChapters() == null) { // load chapters if available - Thread chapterLoader = new Thread() { + if (chapterLoader != null) { + chapterLoader.interrupt(); + } + chapterLoader = new Thread() { @Override public void run() { @@ -1004,6 +1009,9 @@ public class PlaybackService extends Service { public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(ACTION_SHUTDOWN_PLAYBACK_SERVICE)) { schedExecutor.shutdownNow(); + if (chapterLoader != null) { + chapterLoader.interrupt(); + } stop(); media = null; feed = null;