From 8efdee1e8a89b3ca9654596e8407f076b6eed318 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 13 Oct 2018 10:30:56 +0000 Subject: [PATCH] Revert "Halt early when not enabled" This reverts commit 48603f20b6395902d209f90fca6cb23c3ebb4eb9. --- .../java/eu/faircode/email/FragmentOptions.java | 2 +- .../java/eu/faircode/email/ServiceSynchronize.java | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index 308b8975ac..895a0de173 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -61,7 +61,7 @@ public class FragmentOptions extends FragmentEx { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { prefs.edit().putBoolean("enabled", checked).apply(); - ServiceSynchronize.start(getContext()); + ServiceSynchronize.reload(getContext(), "enabled"); } }); diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 5de359323c..936d01a49f 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -179,13 +179,6 @@ public class ServiceSynchronize extends LifecycleService { Log.i(Helper.TAG, "Service command intent=" + intent); super.onStartCommand(intent, flags, startId); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - if (!prefs.getBoolean("enabled", true)) { - Log.i(Helper.TAG, "Not enabled, halt"); - stopSelf(); - return START_STICKY; - } - startForeground(NOTIFICATION_SYNCHRONIZE, getNotificationService(0, 0, 0).build()); DB db = DB.getInstance(this); @@ -1944,6 +1937,13 @@ public class ServiceSynchronize extends LifecycleService { private void start() { EntityLog.log(ServiceSynchronize.this, "Main start"); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ServiceSynchronize.this); + if (!prefs.getBoolean("enabled", true)) { + EntityLog.log(ServiceSynchronize.this, "Not enabled, halt"); + stopSelf(); + return; + } + state = new ServiceState(); state.thread = new Thread(new Runnable() { private List threadState = new ArrayList<>();