Reputation: 122
I wanna add a trigger time to start work on but I can't find a way to do that
with work manger
that's My code
PeriodicWorkRequest alarmWork =
new PeriodicWorkRequest.Builder(
AlarmWorker.class,
interval ,
TimeUnit.MILLISECONDS
).setInputData(bundle).build();
WorkManager.getInstance().enqueue(alarmWork)
Upvotes: 0
Views: 1106
Reputation: 24947
You won't be able to specify exact time at which a Work should be executed. If you need a task to be executed at exact time regardless of Doze mode, you should use AlarmManager.
However you can setup initial delay with WorkManager as follows:
OneTimeWorkRequest mywork=
new OneTimeWorkRequest.Builder(MyWorker.class)
.setInitialDelay(12, TimeUnit.HOURS)
.build();
WorkManager.getInstance().enqueue(mywork);
Upvotes: 2
Reputation: 1
The usage is correct; However, I suppose your interval is smaller than MIN_PERIODIC_INTERVAL_MILLIS
Since the interval must be greater or equal to 15 minutes, PeriodicWorkRequest won't run at the end of the period that you expected.
Upvotes: 0