From c4b059502c87e87def5d81ddacc3649018ce639d Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 27 May 2014 18:37:06 -0400 Subject: [PATCH] better LocalRepoService singleton enforcement We only ever want a single LocalRepoService. Use the values returned by the standard methods for start/stop and bind/unbind as the test for whether the Service is indeed running. --- src/org/fdroid/fdroid/FDroidApp.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/org/fdroid/fdroid/FDroidApp.java b/src/org/fdroid/fdroid/FDroidApp.java index e5d8c13fe..1190f02be 100644 --- a/src/org/fdroid/fdroid/FDroidApp.java +++ b/src/org/fdroid/fdroid/FDroidApp.java @@ -282,17 +282,21 @@ public class FDroidApp extends Application { public static void startLocalRepoService(Context context) { if (!localRepoServiceIsBound) { Context app = context.getApplicationContext(); - app.bindService(new Intent(app, LocalRepoService.class), - serviceConnection, Context.BIND_AUTO_CREATE); - localRepoServiceIsBound = true; + Intent service = new Intent(app, LocalRepoService.class); + localRepoServiceIsBound = app.bindService(service, serviceConnection, + Context.BIND_AUTO_CREATE); + if (localRepoServiceIsBound) + app.startService(service); } } public static void stopLocalRepoService(Context context) { + Context app = context.getApplicationContext(); if (localRepoServiceIsBound) { - context.getApplicationContext().unbindService(serviceConnection); + app.unbindService(serviceConnection); localRepoServiceIsBound = false; } + app.stopService(new Intent(app, LocalRepoService.class)); } public static void restartLocalRepoService() {