diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index c9fcceeefd..564c5f09d0 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -91,7 +91,6 @@ import static android.os.Process.THREAD_PRIORITY_BACKGROUND; public class ServiceSynchronize extends LifecycleService { private ConnectionHelper.NetworkState networkState = new ConnectionHelper.NetworkState(); private Core.State state; - private boolean oneshot = false; private boolean started = false; private int queued = 0; private long lastLost = 0; @@ -99,6 +98,7 @@ public class ServiceSynchronize extends LifecycleService { private ExecutorService queue = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory); private static boolean booted = false; + private static boolean oneshot = false; private static final int CONNECT_BACKOFF_START = 8; // seconds private static final int CONNECT_BACKOFF_MAX = 64; // seconds (totally 2 minutes) @@ -314,9 +314,6 @@ public class ServiceSynchronize extends LifecycleService { am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + ONESHOT_DURATION, piOneshot); else am.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + ONESHOT_DURATION, piOneshot); - - if (!started) - onReload(true, "oneshot start"); } else onReload(true, "oneshot end"); } @@ -1391,10 +1388,12 @@ public class ServiceSynchronize extends LifecycleService { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean enabled = prefs.getBoolean("enabled", true); int pollInterval = prefs.getInt("poll_interval", 0); - if (!enabled || pollInterval > 0) + if (!enabled || pollInterval > 0) { + oneshot = true; ContextCompat.startForegroundService(context, new Intent(context, ServiceSynchronize.class) .setAction("oneshot_start")); + } } static void watchdog(Context context) {