From abe1f8b07ab8e7b49b7b83903608735a91b656d0 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Sun, 12 Aug 2012 14:49:01 +0200 Subject: [PATCH] Added stopForeground() when DownloadSerice has finished waiting for shutdown --- .../danoeh/antennapod/service/DownloadService.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/de/danoeh/antennapod/service/DownloadService.java b/src/de/danoeh/antennapod/service/DownloadService.java index df1236606..3fa355cda 100644 --- a/src/de/danoeh/antennapod/service/DownloadService.java +++ b/src/de/danoeh/antennapod/service/DownloadService.java @@ -98,6 +98,9 @@ public class DownloadService extends Service { /** True if service is running. */ public static boolean isRunning = false; + /** Is started when service waits for shutdown. */ + private Thread waiter; + private final IBinder mBinder = new LocalBinder(); public class LocalBinder extends Binder { public DownloadService getService() { @@ -107,6 +110,9 @@ public class DownloadService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { + if (waiter != null) { + waiter.interrupt(); + } queryDownloads(); return super.onStartCommand(intent, flags, startId); } @@ -179,7 +185,7 @@ public class DownloadService extends Service { if (AppConfig.DEBUG) Log.d(TAG, "Initiating shutdown"); // Wait until PoolExecutor is done - Thread waiter = new Thread() { + waiter = new Thread() { @Override public void run() { syncExecutor.shutdown(); @@ -192,10 +198,12 @@ public class DownloadService extends Service { Log.d(TAG, "Stopping waiting for termination; Result : " + b); - + stopForeground(true); stopSelf(); } catch (InterruptedException e) { e.printStackTrace(); + Log.i(TAG, "Service shutdown was interrupted."); + shutdownInitiated = false; } } };