public abstract class DailyJob extends Job
DailyJob
and you need to use the schedule(JobRequest.Builder, long, long)
to schedule the job.Modifier and Type | Class and Description |
---|---|
static class |
DailyJob.DailyJobResult |
Job.Params, Job.Result
Modifier and Type | Field and Description |
---|---|
(package private) static String |
EXTRA_END_MS |
(package private) static String |
EXTRA_START_MS |
Constructor and Description |
---|
DailyJob() |
Modifier and Type | Method and Description |
---|---|
protected abstract DailyJob.DailyJobResult |
onRunDailyJob(Job.Params params)
This method is invoked from a background thread.
|
protected Job.Result |
onRunJob(Job.Params params)
This method is invoked from a background thread.
|
static int |
schedule(JobRequest.Builder baseBuilder,
long startMs,
long endMs)
Schedules your daily job.
|
static void |
scheduleAsync(JobRequest.Builder baseBuilder,
long startMs,
long endMs)
Helper method to schedule a daily job on a background thread.
|
static void |
scheduleAsync(JobRequest.Builder baseBuilder,
long startMs,
long endMs,
JobRequest.JobScheduledCallback callback)
Helper method to schedule a daily job on a background thread.
|
static int |
startNowOnce(JobRequest.Builder baseBuilder)
Schedules the daily job only once and runs it immediately.
|
cancel, cancel, equals, getContext, getFinishedTimeStamp, getParams, getResult, hashCode, isCanceled, isDeleted, isFinished, isRequirementBatteryNotLowMet, isRequirementChargingMet, isRequirementDeviceIdleMet, isRequirementNetworkTypeMet, isRequirementStorageNotLowMet, meetsRequirements, meetsRequirements, onCancel, onReschedule, runJob, setContext, setRequest, toString
static final String EXTRA_START_MS
static final String EXTRA_END_MS
public static int schedule(@NonNull JobRequest.Builder baseBuilder, long startMs, long endMs)
// schedule between 1am and 6am DailyJob.schedule(builder, TimeUnit.HOURS.toMillis(1), TimeUnit.HOURS.toMillis(6)); // schedule between 8pm and 3am JobRequest.Builder builder = new JobRequest.Builder("MyTag").setRequiresCharging(true); DailyJob.schedule(builder, TimeUnit.HOURS.toMillis(20), TimeUnit.HOURS.toMillis(3));
baseBuilder
- The builder of your daily job.startMs
- The time of the day when the job is allowed to start in milliseconds.endMs
- The time of the day when the job is not allowed to start later in milliseconds.public static void scheduleAsync(@NonNull JobRequest.Builder baseBuilder, long startMs, long endMs)
schedule(JobRequest.Builder, long, long)
.
public static void scheduleAsync(@NonNull JobRequest.Builder baseBuilder, long startMs, long endMs, @NonNull JobRequest.JobScheduledCallback callback)
schedule(JobRequest.Builder, long, long)
.callback
- The callback which is invoked after the request has been scheduled.public static int startNowOnce(@NonNull JobRequest.Builder baseBuilder)
schedule(JobRequest.Builder, long, long)
and this method at the same time to trigger the
execution immediately.baseBuilder
- The builder of your daily job.@NonNull protected final Job.Result onRunJob(@NonNull Job.Params params)
Job
Job
is instantiated. You can identify your Job
with the passed params
.
Job.isCanceled()
frequently for long running jobs and stop your
task if necessary.
PowerManager.WakeLock
is acquired for 3 minutes for each Job
. If your task
needs more time, then you need to create an extra PowerManager.WakeLock
.onRunJob
in class Job
params
- The parameters for this concrete job.Job
. Note that returning Job.Result.RESCHEDULE
for a periodic
Job
is invalid and ignored.@NonNull @WorkerThread protected abstract DailyJob.DailyJobResult onRunDailyJob(@NonNull Job.Params params)
Job
is instantiated and executed. You can identify your Job
with the passed params
.
Job.isCanceled()
frequently for long running jobs and stop your
task if necessary.
PowerManager.WakeLock
is acquired for 3 minutes for each Job
. If your task
needs more time, then you need to create an extra PowerManager.WakeLock
.params
- The parameters for this concrete job.DailyJob
.