diff --git a/app/src/main/java/eu/faircode/email/ReceiverAutoStart.java b/app/src/main/java/eu/faircode/email/ReceiverAutoStart.java index e72d9112f7..891847fa76 100644 --- a/app/src/main/java/eu/faircode/email/ReceiverAutoStart.java +++ b/app/src/main/java/eu/faircode/email/ReceiverAutoStart.java @@ -38,7 +38,7 @@ public class ReceiverAutoStart extends BroadcastReceiver { ServiceSynchronize.boot(context); ServiceSend.boot(context); - WorkerCleanup.queue(context); + WorkerCleanup.queueOnce(context); } } } diff --git a/app/src/main/java/eu/faircode/email/WorkerCleanup.java b/app/src/main/java/eu/faircode/email/WorkerCleanup.java index 30d5a2d1b7..9b23d0b2e9 100644 --- a/app/src/main/java/eu/faircode/email/WorkerCleanup.java +++ b/app/src/main/java/eu/faircode/email/WorkerCleanup.java @@ -24,7 +24,9 @@ import android.content.SharedPreferences; import androidx.annotation.NonNull; import androidx.preference.PreferenceManager; +import androidx.work.Data; import androidx.work.ExistingPeriodicWorkPolicy; +import androidx.work.OneTimeWorkRequest; import androidx.work.PeriodicWorkRequest; import androidx.work.WorkManager; import androidx.work.Worker; @@ -103,8 +105,6 @@ public class WorkerCleanup extends Worker { for (EntityMessage message : db.message().getSnoozed()) EntityMessage.snooze(context, message.id, message.ui_snoozed); - ServiceSynchronize.reschedule(context); - // Clear last search SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); prefs.edit() @@ -223,6 +223,24 @@ public class WorkerCleanup extends Worker { } } + static void queueOnce(Context context) { + try { + Log.i("Queuing " + getName() + " once"); + + Data data = new Data.Builder().putBoolean("manual", true).build(); + + OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(WorkerCleanup.class) + .setInputData(data) + .build(); + WorkManager.getInstance(context).enqueue(workRequest); + + Log.i("Queued " + getName() + " once"); + } catch (IllegalStateException ex) { + // https://issuetracker.google.com/issues/138465476 + Log.w(ex); + } + } + static void cancel(Context context) { try { Log.i("Cancelling " + getName());