From 831db4569e1943bbf3a2cda444e1a866a1343d52 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 11 Sep 2018 16:29:43 +0000 Subject: [PATCH] Fixed restart --- .../eu/faircode/email/ServiceSynchronize.java | 48 ++++++++----------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 8f73382763..70322b5c80 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -1636,37 +1636,31 @@ public class ServiceSynchronize extends LifecycleService { } private void stop() { - if (main != null) { - EntityLog.log(ServiceSynchronize.this, "Main stop " + main); - synchronized (state) { - state.running = false; - state.notifyAll(); - } - - // stop wait or backoff - main.interrupt(); - join(main); - - main = null; - state = null; - - EntityLog.log(ServiceSynchronize.this, "Main stopped " + main); + EntityLog.log(ServiceSynchronize.this, "Main stop " + main); + synchronized (state) { + state.running = false; + state.notifyAll(); } + + // stop wait or backoff + main.interrupt(); + join(main); + + main = null; + state = null; + + EntityLog.log(ServiceSynchronize.this, "Main stopped " + main); } private void restart() { - lifecycle.submit(new Runnable() { - @Override - public void run() { - stop(); - } - }); - lifecycle.submit(new Runnable() { - @Override - public void run() { - start(); - } - }); + if (running) + lifecycle.submit(new Runnable() { + @Override + public void run() { + stop(); + start(); + } + }); } private BroadcastReceiver outboxReceiver = new BroadcastReceiver() {