diff options
author | Alex Ning <chineseperson5@gmail.com> | 2019-08-22 09:30:42 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2019-08-22 09:30:42 +0000 |
commit | 23c76a86cb0ccb71776c13bd619155d35797a26e (patch) | |
tree | a9322ed6855203a71d0673e1074cb9ca64134244 /app/src/main/java/Settings/NotificationPreferenceFragment.java | |
parent | d864ec6d7fa92d18a5d4482fb50907c03f7731a5 (diff) | |
download | infinity-for-reddit-23c76a86cb0ccb71776c13bd619155d35797a26e.tar infinity-for-reddit-23c76a86cb0ccb71776c13bd619155d35797a26e.tar.gz infinity-for-reddit-23c76a86cb0ccb71776c13bd619155d35797a26e.tar.bz2 infinity-for-reddit-23c76a86cb0ccb71776c13bd619155d35797a26e.tar.lz infinity-for-reddit-23c76a86cb0ccb71776c13bd619155d35797a26e.tar.xz infinity-for-reddit-23c76a86cb0ccb71776c13bd619155d35797a26e.tar.zst infinity-for-reddit-23c76a86cb0ccb71776c13bd619155d35797a26e.zip |
Correctly cancel periodic work request by id not by tag. Add an initial delay which is the same time as the interval when start PullNotificationWorker in NotificationPreferenceFragment.
Diffstat (limited to 'app/src/main/java/Settings/NotificationPreferenceFragment.java')
-rw-r--r-- | app/src/main/java/Settings/NotificationPreferenceFragment.java | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/app/src/main/java/Settings/NotificationPreferenceFragment.java b/app/src/main/java/Settings/NotificationPreferenceFragment.java index 17a5d07a..4d9051fe 100644 --- a/app/src/main/java/Settings/NotificationPreferenceFragment.java +++ b/app/src/main/java/Settings/NotificationPreferenceFragment.java @@ -76,12 +76,13 @@ public class NotificationPreferenceFragment extends PreferenceFragmentCompat { new PeriodicWorkRequest.Builder(PullNotificationWorker.class, notificationInterval, TimeUnit.HOURS) .setConstraints(constraints) + .setInitialDelay(notificationInterval, TimeUnit.HOURS) .build(); workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG, - ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest); + ExistingPeriodicWorkPolicy.REPLACE, pullNotificationRequest); } else { - workManager.cancelAllWorkByTag(PullNotificationWorker.WORKER_TAG); + workManager.cancelUniqueWork(PullNotificationWorker.WORKER_TAG); } return true; }); @@ -100,12 +101,13 @@ public class NotificationPreferenceFragment extends PreferenceFragmentCompat { new PeriodicWorkRequest.Builder(PullNotificationWorker.class, notificationInterval, TimeUnit.HOURS) .setConstraints(constraints) + .setInitialDelay(notificationInterval, TimeUnit.HOURS) .build(); workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG, - ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest); + ExistingPeriodicWorkPolicy.REPLACE, pullNotificationRequest); } else { - workManager.cancelAllWorkByTag(PullNotificationWorker.WORKER_TAG); + workManager.cancelUniqueWork(PullNotificationWorker.WORKER_TAG); } return true; |