136
CHAPTER 8: APIs
Table 8-3. JobDispatcher Options
Method
Description
setService(Class)
This is the job class (in Kotlin you must write MyService::class.
java).
setTag(String)
This uniquely identifies the job.
setRecurring(Boolean)
This sets whether this is a recurring job.
setLifetime(Int)
This sets the lifetime of the job. Possible values are Lifetime.
FOREVER and Lifetime.UNTIL_NEXT_BOOT. With FOREVER, the job will
persist even after a device reboot.
setTrigger(Trigger)
This sets when to trigger the job. Possible values are as follows:
• Trigger.NOW: Starts the job immediately
• Trigger.executionWindow(windowStart: Int, windowEnd: Int):
Sets an execution window (in seconds)
• Trigger.contentUriTrigger(uris: List): Watches
content URIs
setReplaceCurrent(Boolean)
This specifies whether to replace an existing job, provided it has the
same tag.
setRetryStrategy(
RetryStrategy)
This sets the retry strategy. Possible values are as follows:
• RetryStrategy.DEFAULT_EXPONENTIAL: Exponential, as in 30s,
1min, 2min, 4min, 8min, and so on.
• RetryStrategy.DEFAULT_LINEAR: Linear, as in 30s, 60s, 90s, 120s,
and so on.
setConstraints(vararg Int)
Here you can set constraints that need to be satisfied for the job to
run. Possible values are as follows:
• Constraint.ON_ANY_NETWORK: Run only if a network is available.
• Constraint.ON_UNMETERED_NETWORK: Run only if an unmetered
network is available.
• Constraint.DEVICE_CHARGING: Run only if the device is plugged in.
• Constraint.DEVICE_IDLE: Run only if the device is idle.
setExtras(Bundle)
Use this to set extra data. These will be passed to onStartJob()
in the job service class.
Do'stlaringiz bilan baham: |