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.
This commit is contained in:
Hans-Christoph Steiner 2014-05-27 18:37:06 -04:00
parent 2c594cae5d
commit c4b059502c

View File

@ -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() {