本文整理汇总了Java中com.firebase.jobdispatcher.Job.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java Job.Builder方法的具体用法?Java Job.Builder怎么用?Java Job.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.firebase.jobdispatcher.Job
的用法示例。
在下文中一共展示了Job.Builder方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scheduleBackgroundJob
import com.firebase.jobdispatcher.Job; //导入方法依赖的package包/类
/**
* Schedule a new background job that will be triggered via {@link FirebaseJobDispatcher}.
*/
private boolean scheduleBackgroundJob(String jobKey, int period, boolean persist,
boolean override, int networkType, boolean requiresCharging, Bundle jobBundle) {
int periodInSeconds = (int) TimeUnit.MILLISECONDS.toSeconds(period);
Job.Builder jobBuilder = mJobDispatcher.newJobBuilder()
.setService(BackgroundJob.class)
.setExtras(jobBundle)
.setTag(jobKey)
.setTrigger(Trigger.executionWindow(periodInSeconds, periodInSeconds))
.setLifetime(persist ? Lifetime.FOREVER : Lifetime.UNTIL_NEXT_BOOT)
.setRecurring(true)
.setReplaceCurrent(override)
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR);
if (requiresCharging) {
jobBuilder.addConstraint(Constraint.DEVICE_CHARGING);
}
if (networkType == Constraint.ON_ANY_NETWORK || networkType == Constraint.ON_UNMETERED_NETWORK) {
jobBuilder.addConstraint(networkType);
}
if (mJobDispatcher.schedule(jobBuilder.build()) == SCHEDULE_RESULT_SUCCESS) {
Log.d(LOG_TAG, "Successfully scheduled: " + jobKey);
return true;
} else {
Log.w(LOG_TAG, "Failed to schedule: " + jobKey);
return false;
}
}
示例2: setup
import com.firebase.jobdispatcher.Job; //导入方法依赖的package包/类
private static boolean setup(@NonNull final Context context, final int timeInSeconds, final boolean waitUnmeteredNetwork) {
if (!isBackupActive(context)) {
return false;
}
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
Job.Builder obBuilder = dispatcher.newJobBuilder()
// the JobService that will be called
.setService(DriveBackupService.class)
// uniquely identifies the job
.setTag(DriveBackupService.TAG)
// one-off job
.setRecurring(false)
// persist past a device reboot (requires boot receiver permission)
.setLifetime(Lifetime.FOREVER)
// overwrite an existing job with the same tag
.setReplaceCurrent(true)
// retry with exponential backoff
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR);
if (waitUnmeteredNetwork) {
// only run on an unmetered network
obBuilder.addConstraint(Constraint.ON_UNMETERED_NETWORK);
}
if (timeInSeconds >= 0) {
// Run after selected time and any time in one hour
obBuilder.setTrigger(Trigger.executionWindow(timeInSeconds, timeInSeconds + 1800));
} else {
obBuilder.setTrigger(Trigger.NOW);
}
return dispatcher.schedule(obBuilder.build()) == FirebaseJobDispatcher.SCHEDULE_RESULT_SUCCESS;
}