Added stopForeground() when DownloadSerice has finished waiting for

shutdown
This commit is contained in:
daniel oeh 2012-08-12 14:49:01 +02:00
parent 41f352d3f9
commit abe1f8b07a
1 changed files with 10 additions and 2 deletions

View File

@ -98,6 +98,9 @@ public class DownloadService extends Service {
/** True if service is running. */ /** True if service is running. */
public static boolean isRunning = false; public static boolean isRunning = false;
/** Is started when service waits for shutdown. */
private Thread waiter;
private final IBinder mBinder = new LocalBinder(); private final IBinder mBinder = new LocalBinder();
public class LocalBinder extends Binder { public class LocalBinder extends Binder {
public DownloadService getService() { public DownloadService getService() {
@ -107,6 +110,9 @@ public class DownloadService extends Service {
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
if (waiter != null) {
waiter.interrupt();
}
queryDownloads(); queryDownloads();
return super.onStartCommand(intent, flags, startId); return super.onStartCommand(intent, flags, startId);
} }
@ -179,7 +185,7 @@ public class DownloadService extends Service {
if (AppConfig.DEBUG) if (AppConfig.DEBUG)
Log.d(TAG, "Initiating shutdown"); Log.d(TAG, "Initiating shutdown");
// Wait until PoolExecutor is done // Wait until PoolExecutor is done
Thread waiter = new Thread() { waiter = new Thread() {
@Override @Override
public void run() { public void run() {
syncExecutor.shutdown(); syncExecutor.shutdown();
@ -192,10 +198,12 @@ public class DownloadService extends Service {
Log.d(TAG, Log.d(TAG,
"Stopping waiting for termination; Result : " "Stopping waiting for termination; Result : "
+ b); + b);
stopForeground(true);
stopSelf(); stopSelf();
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
Log.i(TAG, "Service shutdown was interrupted.");
shutdownInitiated = false;
} }
} }
}; };