mrpep
mrpep

Reputation: 131

EverNote android-job: How can I run a job at a specific time once a day every week?

I'm developing a weekly scheduler in android and I'm interesting in a periodic job (once a week for example) that is fired at a specific time (for example at 4.00 PM) with evernote android-job

I have read this post

https://github.com/evernote/android-job/blob/master/FAQ.md#how-can-i-run-a-job-at-a-specific-time-once-a-day

and I can run a job every day once a day, but it is not my case. If I set

new JobRequest.Builder( MY_TAG ) .setExact( TimeUnit.HOURS.toMillis( 16 ) + TimeUnit.MINUTES.toMillis( 0 )) .setPeriodic( TimeUnit.DAYS.toMillis( 7 ), TimeUnit.MINUTES.toMillis(5) ) .setPersisted(true) .build() .schedule();

I have this error

"Can't call setExact() on a periodic job"

Can someone help me?

Upvotes: 0

Views: 1788

Answers (2)

muhwid
muhwid

Reputation: 1

try this dude.

public final class MyDailyJob extends DailyJob {
public static final String TAG = "MyDailyJob";
public static void schedule() {
    // schedule between 1 and 6 AM
    DailyJob.schedule(new JobRequest.Builder(TAG), TimeUnit.HOURS.toMillis(1), TimeUnit.HOURS.toMillis(6));
}

@NonNull
@Override
protected DailyJobResult onRunDailyJob(Params params) {
    return DailyJobResult.SUCCESS;
 }
}

reference link

Upvotes: 0

Shyamnath Mallinathan
Shyamnath Mallinathan

Reputation: 736

setExact() and setPeriodic() are two distinct features,they cannot be coupled. If you want to use setExact periodically, You'd have to programatically schedule a job again once the previously set job has run.

Upvotes: 2

Related Questions