当前位置: 首页>>代码示例>>Java>>正文


Java Job.Builder方法代码示例

本文整理汇总了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;
  }
}
 
开发者ID:vikeri,项目名称:react-native-background-job,代码行数:30,代码来源:BackgroundJobModule.java

示例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;
}
 
开发者ID:canyapan,项目名称:DietDiaryApp,代码行数:36,代码来源:DriveBackupServiceHelper.java


注:本文中的com.firebase.jobdispatcher.Job.Builder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。