Java源码示例:com.firebase.jobdispatcher.Constraint
示例1
public static void startSignInSocial(Context context, Bundle bundle){
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
Job myJob = dispatcher.newJobBuilder()
// the JobService that will be called
.setService(SessionJobService.class)
// uniquely identifies the job
.setTag(SIGN_IN_SOCIAL_ACTION)
// one-off job
.setRecurring(false)
// start between 0 and 60 seconds from now
.setTrigger(Trigger.executionWindow(0, 60))
// don't overwrite an existing job with the same tag
.setReplaceCurrent(false)
// constraints that need to be satisfied for the job to run
.setConstraints(
// only run on an unmetered network
Constraint.ON_UNMETERED_NETWORK
)
.setExtras(bundle)
.build();
dispatcher.mustSchedule(myJob);
}
示例2
public static void scheduleFirebaseBackgroundUpload(Context context) {
FirebaseJobDispatcher jobDispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
jobDispatcher.mustSchedule(
jobDispatcher.newJobBuilder()
.setTag(BACKGROUND_UPLOAD_JOB_TAG)
.setService(FirebaseJobService.class)
.setConstraints(
Constraint.ON_UNMETERED_NETWORK,
Constraint.DEVICE_CHARGING)
.setTrigger(Trigger.executionWindow(
0, // can start immediately
(int) TimeUnit.DAYS.toSeconds(1))) // wait at most a day
.build());
}
示例3
public static void scheduleUpdateJob(Context context) {
FirebaseJobDispatcher jobDispatcher =
new FirebaseJobDispatcher(new GooglePlayDriver(context));
jobDispatcher.schedule(jobDispatcher.newJobBuilder()
.setTag(UPDATE_JOB_TAG)
.setService(EarthquakeUpdateJobService.class)
.setConstraints(Constraint.ON_ANY_NETWORK)
.build());
}
示例4
private void scheduleNextUpdate(Context context, JobParameters job) {
if (job.getTag().equals(UPDATE_JOB_TAG)) {
SharedPreferences prefs =
PreferenceManager.getDefaultSharedPreferences(this);
int updateFreq = Integer.parseInt(
prefs.getString(PreferencesActivity.PREF_UPDATE_FREQ, "60"));
boolean autoUpdateChecked =
prefs.getBoolean(PreferencesActivity.PREF_AUTO_UPDATE, false);
if (autoUpdateChecked) {
FirebaseJobDispatcher jobDispatcher =
new FirebaseJobDispatcher(new GooglePlayDriver(context));
jobDispatcher.schedule(jobDispatcher.newJobBuilder()
.setTag(PERIODIC_JOB_TAG)
.setService(EarthquakeUpdateJobService.class)
.setConstraints(Constraint.ON_ANY_NETWORK)
.setReplaceCurrent(true)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(
updateFreq*60 / 2,
updateFreq*60))
.setLifetime(Lifetime.FOREVER)
.build());
}
}
}
示例5
public static void scheduleUpdateJob(Context context) {
FirebaseJobDispatcher jobDispatcher =
new FirebaseJobDispatcher(new GooglePlayDriver(context));
jobDispatcher.schedule(jobDispatcher.newJobBuilder()
.setTag(UPDATE_JOB_TAG)
.setService(EarthquakeUpdateJobService.class)
.setConstraints(Constraint.ON_ANY_NETWORK)
.build());
}
示例6
private void scheduleNextUpdate(Context context, JobParameters job) {
if (job.getTag().equals(UPDATE_JOB_TAG)) {
SharedPreferences prefs =
PreferenceManager.getDefaultSharedPreferences(this);
int updateFreq = Integer.parseInt(
prefs.getString(PreferencesActivity.PREF_UPDATE_FREQ, "60"));
boolean autoUpdateChecked =
prefs.getBoolean(PreferencesActivity.PREF_AUTO_UPDATE, false);
if (autoUpdateChecked) {
FirebaseJobDispatcher jobDispatcher =
new FirebaseJobDispatcher(new GooglePlayDriver(context));
jobDispatcher.schedule(jobDispatcher.newJobBuilder()
.setTag(PERIODIC_JOB_TAG)
.setService(EarthquakeUpdateJobService.class)
.setConstraints(Constraint.ON_ANY_NETWORK)
.setReplaceCurrent(true)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(
updateFreq*60 / 2,
updateFreq*60))
.setLifetime(Lifetime.FOREVER)
.build());
}
}
}
示例7
public static void scheduleUpdateJob(Context context) {
FirebaseJobDispatcher jobDispatcher =
new FirebaseJobDispatcher(new GooglePlayDriver(context));
jobDispatcher.schedule(jobDispatcher.newJobBuilder()
.setTag(UPDATE_JOB_TAG)
.setService(EarthquakeUpdateJobService.class)
.setConstraints(Constraint.ON_ANY_NETWORK)
.build());
}
示例8
private void scheduleNextUpdate(Context context, JobParameters job) {
if (job.getTag().equals(UPDATE_JOB_TAG)) {
SharedPreferences prefs =
PreferenceManager.getDefaultSharedPreferences(this);
int updateFreq = Integer.parseInt(
prefs.getString(PreferencesActivity.PREF_UPDATE_FREQ, "60"));
boolean autoUpdateChecked =
prefs.getBoolean(PreferencesActivity.PREF_AUTO_UPDATE, false);
if (autoUpdateChecked) {
FirebaseJobDispatcher jobDispatcher =
new FirebaseJobDispatcher(new GooglePlayDriver(context));
jobDispatcher.schedule(jobDispatcher.newJobBuilder()
.setTag(PERIODIC_JOB_TAG)
.setService(EarthquakeUpdateJobService.class)
.setConstraints(Constraint.ON_ANY_NETWORK)
.setReplaceCurrent(true)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(
updateFreq*60 / 2,
updateFreq*60))
.setLifetime(Lifetime.FOREVER)
.build());
}
}
}
示例9
public static void scheduleUpdateJob(Context context) {
FirebaseJobDispatcher jobDispatcher =
new FirebaseJobDispatcher(new GooglePlayDriver(context));
jobDispatcher.schedule(jobDispatcher.newJobBuilder()
.setTag(UPDATE_JOB_TAG)
.setService(EarthquakeUpdateJobService.class)
.setConstraints(Constraint.ON_ANY_NETWORK)
.build());
}
示例10
private void scheduleNextUpdate(Context context, JobParameters job) {
if (job.getTag().equals(UPDATE_JOB_TAG)) {
SharedPreferences prefs =
PreferenceManager.getDefaultSharedPreferences(this);
int updateFreq = Integer.parseInt(
prefs.getString(PreferencesActivity.PREF_UPDATE_FREQ, "60"));
boolean autoUpdateChecked =
prefs.getBoolean(PreferencesActivity.PREF_AUTO_UPDATE, false);
if (autoUpdateChecked) {
FirebaseJobDispatcher jobDispatcher =
new FirebaseJobDispatcher(new GooglePlayDriver(context));
jobDispatcher.schedule(jobDispatcher.newJobBuilder()
.setTag(PERIODIC_JOB_TAG)
.setService(EarthquakeUpdateJobService.class)
.setConstraints(Constraint.ON_ANY_NETWORK)
.setReplaceCurrent(true)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(
updateFreq*60 / 2,
updateFreq*60))
.setLifetime(Lifetime.FOREVER)
.build());
}
}
}
示例11
public static void scheduleUpdateJob(Context context) {
FirebaseJobDispatcher jobDispatcher =
new FirebaseJobDispatcher(new GooglePlayDriver(context));
jobDispatcher.schedule(jobDispatcher.newJobBuilder()
.setTag(UPDATE_JOB_TAG)
.setService(EarthquakeUpdateJobService.class)
.setConstraints(Constraint.ON_ANY_NETWORK)
.build());
}
示例12
private void scheduleNextUpdate(Context context, JobParameters job) {
if (job.getTag().equals(UPDATE_JOB_TAG)) {
SharedPreferences prefs =
PreferenceManager.getDefaultSharedPreferences(this);
int updateFreq = Integer.parseInt(
prefs.getString(PreferencesActivity.PREF_UPDATE_FREQ, "60"));
boolean autoUpdateChecked =
prefs.getBoolean(PreferencesActivity.PREF_AUTO_UPDATE, false);
if (autoUpdateChecked) {
FirebaseJobDispatcher jobDispatcher =
new FirebaseJobDispatcher(new GooglePlayDriver(context));
jobDispatcher.schedule(jobDispatcher.newJobBuilder()
.setTag(PERIODIC_JOB_TAG)
.setService(EarthquakeUpdateJobService.class)
.setConstraints(Constraint.ON_ANY_NETWORK)
.setReplaceCurrent(true)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(
updateFreq*60 / 2,
updateFreq*60))
.setLifetime(Lifetime.FOREVER)
.build());
}
}
}
示例13
public static void scheduleUpdateJob(Context context) {
FirebaseJobDispatcher jobDispatcher =
new FirebaseJobDispatcher(new GooglePlayDriver(context));
jobDispatcher.schedule(jobDispatcher.newJobBuilder()
.setTag(UPDATE_JOB_TAG)
.setService(EarthquakeUpdateJobService.class)
.setConstraints(Constraint.ON_ANY_NETWORK)
.build());
}
示例14
private void scheduleNextUpdate(Context context, JobParameters job) {
if (job.getTag().equals(UPDATE_JOB_TAG)) {
SharedPreferences prefs =
PreferenceManager.getDefaultSharedPreferences(this);
int updateFreq = Integer.parseInt(
prefs.getString(PreferencesActivity.PREF_UPDATE_FREQ, "60"));
boolean autoUpdateChecked =
prefs.getBoolean(PreferencesActivity.PREF_AUTO_UPDATE, false);
if (autoUpdateChecked) {
FirebaseJobDispatcher jobDispatcher =
new FirebaseJobDispatcher(new GooglePlayDriver(context));
jobDispatcher.schedule(jobDispatcher.newJobBuilder()
.setTag(PERIODIC_JOB_TAG)
.setService(EarthquakeUpdateJobService.class)
.setConstraints(Constraint.ON_ANY_NETWORK)
.setReplaceCurrent(true)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(
updateFreq*60 / 2,
updateFreq*60))
.setLifetime(Lifetime.FOREVER)
.build());
}
}
}
示例15
public static void scheduleUpdateJob(Context context) {
FirebaseJobDispatcher jobDispatcher =
new FirebaseJobDispatcher(new GooglePlayDriver(context));
jobDispatcher.schedule(jobDispatcher.newJobBuilder()
.setTag(UPDATE_JOB_TAG)
.setService(EarthquakeUpdateJobService.class)
.setConstraints(Constraint.ON_ANY_NETWORK)
.build());
}
示例16
private void scheduleNextUpdate(Context context, JobParameters job) {
if (job.getTag().equals(UPDATE_JOB_TAG)) {
SharedPreferences prefs =
PreferenceManager.getDefaultSharedPreferences(this);
int updateFreq = Integer.parseInt(
prefs.getString(PreferencesActivity.PREF_UPDATE_FREQ, "60"));
boolean autoUpdateChecked =
prefs.getBoolean(PreferencesActivity.PREF_AUTO_UPDATE, false);
if (autoUpdateChecked) {
FirebaseJobDispatcher jobDispatcher =
new FirebaseJobDispatcher(new GooglePlayDriver(context));
jobDispatcher.schedule(jobDispatcher.newJobBuilder()
.setTag(PERIODIC_JOB_TAG)
.setService(EarthquakeUpdateJobService.class)
.setConstraints(Constraint.ON_ANY_NETWORK)
.setReplaceCurrent(true)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(
updateFreq*60 / 2,
updateFreq*60))
.setLifetime(Lifetime.FOREVER)
.build());
}
}
}
示例17
public static void scheduleUpdateJob(Context context) {
FirebaseJobDispatcher jobDispatcher =
new FirebaseJobDispatcher(new GooglePlayDriver(context));
jobDispatcher.schedule(jobDispatcher.newJobBuilder()
.setTag(UPDATE_JOB_TAG)
.setService(EarthquakeUpdateJobService.class)
.setConstraints(Constraint.ON_ANY_NETWORK)
.build());
}
示例18
private void scheduleNextUpdate(Context context, JobParameters job) {
if (job.getTag().equals(UPDATE_JOB_TAG)) {
SharedPreferences prefs =
PreferenceManager.getDefaultSharedPreferences(this);
int updateFreq = Integer.parseInt(
prefs.getString(PreferencesActivity.PREF_UPDATE_FREQ, "60"));
boolean autoUpdateChecked =
prefs.getBoolean(PreferencesActivity.PREF_AUTO_UPDATE, false);
if (autoUpdateChecked) {
FirebaseJobDispatcher jobDispatcher =
new FirebaseJobDispatcher(new GooglePlayDriver(context));
jobDispatcher.schedule(jobDispatcher.newJobBuilder()
.setTag(PERIODIC_JOB_TAG)
.setService(EarthquakeUpdateJobService.class)
.setConstraints(Constraint.ON_ANY_NETWORK)
.setReplaceCurrent(true)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(
updateFreq*60 / 2,
updateFreq*60))
.setLifetime(Lifetime.FOREVER)
.build());
}
}
}
示例19
synchronized public static void scheduleChargingReminder(@NonNull final Context context) {
// COMPLETED (17) If the job has already been initialized, return
if (sInitialized) return;
// COMPLETED (18) Create a new GooglePlayDriver
Driver driver = new GooglePlayDriver(context);
// COMPLETED (19) Create a new FirebaseJobDispatcher with the driver
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(driver);
// COMPLETED (20) Use FirebaseJobDispatcher's newJobBuilder method to build a job which:
// - has WaterReminderFirebaseJobService as it's service
// - has the tag REMINDER_JOB_TAG
// - only triggers if the device is charging
// - has the lifetime of the job as forever
// - has the job recur
// - occurs every 15 minutes with a window of 15 minutes. You can do this using a
// setTrigger, passing in a Trigger.executionWindow
// - replaces the current job if it's already running
// Finally, you should build the job.
Job constraintReminderJob = dispatcher.newJobBuilder()
.setService(WaterReminderFirebaseJobService.class)
.setTag(REMINDER_JOB_TAG)
.setConstraints(Constraint.DEVICE_CHARGING)
.setLifetime(Lifetime.FOREVER)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(
REMINDER_INTERVAL_SECONDS,
REMINDER_INTERVAL_SECONDS + SYNC_FLEXTIME_SECONDS))
.setReplaceCurrent(true)
.build();
// COMPLETED (21) Use dispatcher's schedule method to schedule the job
dispatcher.schedule(constraintReminderJob);
// COMPLETED (22) Set sInitialized to true to mark that we're done setting up the job
sInitialized = true;
}
示例20
/**
* 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;
}
}
示例21
@Nullable @Override public Map<String, Object> getConstants() {
Log.d(LOG_TAG, "Getting constants");
HashMap<String, Object> constants = new HashMap<>();
constants.put(NETWORK_TYPE_UNMETERED, Constraint.ON_UNMETERED_NETWORK);
constants.put(NETWORK_TYPE_ANY, Constraint.ON_ANY_NETWORK);
return constants;
}
示例22
public ScheduleRunnable(FirebaseJobDispatcher dispatcher) {
this.dispatcher = dispatcher;
this.jobToSchedule = dispatcher.newJobBuilder()
.setTag("downloader_job")
.setService(DownloaderJobService.class)
.setConstraints(Constraint.ON_ANY_NETWORK)
.build();
}
示例23
synchronized public static void scheduleChargingReminder(@NonNull final Context context) {
if (sInitialized) return;
Driver driver = new GooglePlayDriver(context);
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(driver);
/* Create the Job to periodically create reminders to drink water */
Job constraintReminderJob = dispatcher.newJobBuilder()
/* The Service that will be used to write to preferences */
.setService(WaterReminderFirebaseJobService.class)
/*
* Set the UNIQUE tag used to identify this Job.
*/
.setTag(REMINDER_JOB_TAG)
/*
* Network constraints on which this Job should run. In this app, we're using the
* device charging constraint so that the job only executes if the device is
* charging.
*
* In a normal app, it might be a good idea to include a preference for this,
* as different users may have different preferences on when you should be
* syncing your application's data.
*/
.setConstraints(Constraint.DEVICE_CHARGING)
/*
* setLifetime sets how long this job should persist. The options are to keep the
* Job "forever" or to have it die the next time the device boots up.
*/
.setLifetime(Lifetime.FOREVER)
/*
* We want these reminders to continuously happen, so we tell this Job to recur.
*/
.setRecurring(true)
/*
* We want the reminders to happen every 15 minutes or so. The first argument for
* Trigger class's static executionWindow method is the start of the time frame
* when the
* job should be performed. The second argument is the latest point in time at
* which the data should be synced. Please note that this end time is not
* guaranteed, but is more of a guideline for FirebaseJobDispatcher to go off of.
*/
.setTrigger(Trigger.executionWindow(
REMINDER_INTERVAL_SECONDS,
REMINDER_INTERVAL_SECONDS + SYNC_FLEXTIME_SECONDS))
/*
* If a Job with the tag with provided already exists, this new job will replace
* the old one.
*/
.setReplaceCurrent(true)
/* Once the Job is ready, call the builder's build method to return the Job */
.build();
/* Schedule the Job with the dispatcher */
dispatcher.schedule(constraintReminderJob);
/* The job has been initialized */
sInitialized = true;
}
示例24
synchronized public static void scheduleChargingReminder(@NonNull final Context context) {
if (sInitialized) return;
Driver driver = new GooglePlayDriver(context);
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(driver);
/* Create the Job to periodically create reminders to drink water */
Job constraintReminderJob = dispatcher.newJobBuilder()
/* The Service that will be used to write to preferences */
.setService(WaterReminderFirebaseJobService.class)
/*
* Set the UNIQUE tag used to identify this Job.
*/
.setTag(REMINDER_JOB_TAG)
/*
* Network constraints on which this Job should run. In this app, we're using the
* device charging constraint so that the job only executes if the device is
* charging.
*
* In a normal app, it might be a good idea to include a preference for this,
* as different users may have different preferences on when you should be
* syncing your application's data.
*/
.setConstraints(Constraint.DEVICE_CHARGING)
/*
* setLifetime sets how long this job should persist. The options are to keep the
* Job "forever" or to have it die the next time the device boots up.
*/
.setLifetime(Lifetime.FOREVER)
/*
* We want these reminders to continuously happen, so we tell this Job to recur.
*/
.setRecurring(true)
/*
* We want the reminders to happen every 15 minutes or so. The first argument for
* Trigger class's static executionWindow method is the start of the time frame
* when the
* job should be performed. The second argument is the latest point in time at
* which the data should be synced. Please note that this end time is not
* guaranteed, but is more of a guideline for FirebaseJobDispatcher to go off of.
*/
.setTrigger(Trigger.executionWindow(
REMINDER_INTERVAL_SECONDS,
REMINDER_INTERVAL_SECONDS + SYNC_FLEXTIME_SECONDS))
/*
* If a Job with the tag with provided already exists, this new job will replace
* the old one.
*/
.setReplaceCurrent(true)
/* Once the Job is ready, call the builder's build method to return the Job */
.build();
/* Schedule the Job with the dispatcher */
dispatcher.schedule(constraintReminderJob);
/* The job has been initialized */
sInitialized = true;
}
示例25
/**
* Schedules a repeating sync of Sunshine's weather data using FirebaseJobDispatcher.
* @param context Context used to create the GooglePlayDriver that powers the
* FirebaseJobDispatcher
*/
static void scheduleFirebaseJobDispatcherSync(@NonNull final Context context) {
Driver driver = new GooglePlayDriver(context);
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(driver);
/* Create the Job to periodically sync Sunshine */
Job syncSunshineJob = dispatcher.newJobBuilder()
/* The Service that will be used to sync Sunshine's data */
.setService(SunshineFirebaseJobService.class)
/* Set the UNIQUE tag used to identify this Job */
.setTag(SUNSHINE_SYNC_TAG)
/*
* Network constraints on which this Job should run. We choose to run on any
* network, but you can also choose to run only on un-metered networks or when the
* device is charging. It might be a good idea to include a preference for this,
* as some users may not want to download any data on their mobile plan. ($$$)
*/
.setConstraints(Constraint.ON_ANY_NETWORK)
/*
* setLifetime sets how long this job should persist. The options are to keep the
* Job "forever" or to have it die the next time the device boots up.
*/
.setLifetime(Lifetime.FOREVER)
/*
* We want Sunshine's weather data to stay up to date, so we tell this Job to recur.
*/
.setRecurring(true)
/*
* We want the weather data to be synced every 3 to 4 hours. The first argument for
* Trigger's static executionWindow method is the start of the time frame when the
* sync should be performed. The second argument is the latest point in time at
* which the data should be synced. Please note that this end time is not
* guaranteed, but is more of a guideline for FirebaseJobDispatcher to go off of.
*/
.setTrigger(Trigger.executionWindow(
SYNC_INTERVAL_SECONDS,
SYNC_INTERVAL_SECONDS + SYNC_FLEXTIME_SECONDS))
/*
* If a Job with the tag with provided already exists, this new job will replace
* the old one.
*/
.setReplaceCurrent(true)
/* Once the Job is ready, call the builder's build method to return the Job */
.build();
/* Schedule the Job with the dispatcher */
dispatcher.schedule(syncSunshineJob);
}
示例26
/**
* Schedules a repeating sync of Sunshine's weather data using FirebaseJobDispatcher.
* @param context Context used to create the GooglePlayDriver that powers the
* FirebaseJobDispatcher
*/
static void scheduleFirebaseJobDispatcherSync(@NonNull final Context context) {
Driver driver = new GooglePlayDriver(context);
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(driver);
/* Create the Job to periodically sync Sunshine */
Job syncSunshineJob = dispatcher.newJobBuilder()
/* The Service that will be used to sync Sunshine's data */
.setService(SunshineFirebaseJobService.class)
/* Set the UNIQUE tag used to identify this Job */
.setTag(SUNSHINE_SYNC_TAG)
/*
* Network constraints on which this Job should run. We choose to run on any
* network, but you can also choose to run only on un-metered networks or when the
* device is charging. It might be a good idea to include a preference for this,
* as some users may not want to download any data on their mobile plan. ($$$)
*/
.setConstraints(Constraint.ON_ANY_NETWORK)
/*
* setLifetime sets how long this job should persist. The options are to keep the
* Job "forever" or to have it die the next time the device boots up.
*/
.setLifetime(Lifetime.FOREVER)
/*
* We want Sunshine's weather data to stay up to date, so we tell this Job to recur.
*/
.setRecurring(true)
/*
* We want the weather data to be synced every 3 to 4 hours. The first argument for
* Trigger's static executionWindow method is the start of the time frame when the
* sync should be performed. The second argument is the latest point in time at
* which the data should be synced. Please note that this end time is not
* guaranteed, but is more of a guideline for FirebaseJobDispatcher to go off of.
*/
.setTrigger(Trigger.executionWindow(
SYNC_INTERVAL_SECONDS,
SYNC_INTERVAL_SECONDS + SYNC_FLEXTIME_SECONDS))
/*
* If a Job with the tag with provided already exists, this new job will replace
* the old one.
*/
.setReplaceCurrent(true)
/* Once the Job is ready, call the builder's build method to return the Job */
.build();
/* Schedule the Job with the dispatcher */
dispatcher.schedule(syncSunshineJob);
}
示例27
/**
* Schedules a repeating sync of Sunshine's weather data using FirebaseJobDispatcher.
* @param context Context used to create the GooglePlayDriver that powers the
* FirebaseJobDispatcher
*/
static void scheduleFirebaseJobDispatcherSync(@NonNull final Context context) {
Driver driver = new GooglePlayDriver(context);
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(driver);
/* Create the Job to periodically sync Sunshine */
Job syncSunshineJob = dispatcher.newJobBuilder()
/* The Service that will be used to sync Sunshine's data */
.setService(SunshineFirebaseJobService.class)
/* Set the UNIQUE tag used to identify this Job */
.setTag(SUNSHINE_SYNC_TAG)
/*
* Network constraints on which this Job should run. We choose to run on any
* network, but you can also choose to run only on un-metered networks or when the
* device is charging. It might be a good idea to include a preference for this,
* as some users may not want to download any data on their mobile plan. ($$$)
*/
.setConstraints(Constraint.ON_ANY_NETWORK)
/*
* setLifetime sets how long this job should persist. The options are to keep the
* Job "forever" or to have it die the next time the device boots up.
*/
.setLifetime(Lifetime.FOREVER)
/*
* We want Sunshine's weather data to stay up to date, so we tell this Job to recur.
*/
.setRecurring(true)
/*
* We want the weather data to be synced every 3 to 4 hours. The first argument for
* Trigger's static executionWindow method is the start of the time frame when the
* sync should be performed. The second argument is the latest point in time at
* which the data should be synced. Please note that this end time is not
* guaranteed, but is more of a guideline for FirebaseJobDispatcher to go off of.
*/
.setTrigger(Trigger.executionWindow(
SYNC_INTERVAL_SECONDS,
SYNC_INTERVAL_SECONDS + SYNC_FLEXTIME_SECONDS))
/*
* If a Job with the tag with provided already exists, this new job will replace
* the old one.
*/
.setReplaceCurrent(true)
/* Once the Job is ready, call the builder's build method to return the Job */
.build();
/* Schedule the Job with the dispatcher */
dispatcher.schedule(syncSunshineJob);
}
示例28
/**
* Schedules a repeating sync of Sunshine's weather data using FirebaseJobDispatcher.
* @param context Context used to create the GooglePlayDriver that powers the
* FirebaseJobDispatcher
*/
static void scheduleFirebaseJobDispatcherSync(@NonNull final Context context) {
Driver driver = new GooglePlayDriver(context);
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(driver);
/* Create the Job to periodically sync Sunshine */
Job syncSunshineJob = dispatcher.newJobBuilder()
/* The Service that will be used to sync Sunshine's data */
.setService(SunshineFirebaseJobService.class)
/* Set the UNIQUE tag used to identify this Job */
.setTag(SUNSHINE_SYNC_TAG)
/*
* Network constraints on which this Job should run. We choose to run on any
* network, but you can also choose to run only on un-metered networks or when the
* device is charging. It might be a good idea to include a preference for this,
* as some users may not want to download any data on their mobile plan. ($$$)
*/
.setConstraints(Constraint.ON_ANY_NETWORK)
/*
* setLifetime sets how long this job should persist. The options are to keep the
* Job "forever" or to have it die the next time the device boots up.
*/
.setLifetime(Lifetime.FOREVER)
/*
* We want Sunshine's weather data to stay up to date, so we tell this Job to recur.
*/
.setRecurring(true)
/*
* We want the weather data to be synced every 3 to 4 hours. The first argument for
* Trigger's static executionWindow method is the start of the time frame when the
* sync should be performed. The second argument is the latest point in time at
* which the data should be synced. Please note that this end time is not
* guaranteed, but is more of a guideline for FirebaseJobDispatcher to go off of.
*/
.setTrigger(Trigger.executionWindow(
SYNC_INTERVAL_SECONDS,
SYNC_INTERVAL_SECONDS + SYNC_FLEXTIME_SECONDS))
/*
* If a Job with the tag with provided already exists, this new job will replace
* the old one.
*/
.setReplaceCurrent(true)
/* Once the Job is ready, call the builder's build method to return the Job */
.build();
/* Schedule the Job with the dispatcher */
dispatcher.schedule(syncSunshineJob);
}
示例29
/**
* Schedules a repeating sync of Sunshine's weather data using FirebaseJobDispatcher.
* @param context Context used to create the GooglePlayDriver that powers the
* FirebaseJobDispatcher
*/
static void scheduleFirebaseJobDispatcherSync(@NonNull final Context context) {
Driver driver = new GooglePlayDriver(context);
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(driver);
/* Create the Job to periodically sync Sunshine */
Job syncSunshineJob = dispatcher.newJobBuilder()
/* The Service that will be used to sync Sunshine's data */
.setService(SunshineFirebaseJobService.class)
/* Set the UNIQUE tag used to identify this Job */
.setTag(SUNSHINE_SYNC_TAG)
/*
* Network constraints on which this Job should run. We choose to run on any
* network, but you can also choose to run only on un-metered networks or when the
* device is charging. It might be a good idea to include a preference for this,
* as some users may not want to download any data on their mobile plan. ($$$)
*/
.setConstraints(Constraint.ON_ANY_NETWORK)
/*
* setLifetime sets how long this job should persist. The options are to keep the
* Job "forever" or to have it die the next time the device boots up.
*/
.setLifetime(Lifetime.FOREVER)
/*
* We want Sunshine's weather data to stay up to date, so we tell this Job to recur.
*/
.setRecurring(true)
/*
* We want the weather data to be synced every 3 to 4 hours. The first argument for
* Trigger's static executionWindow method is the start of the time frame when the
* sync should be performed. The second argument is the latest point in time at
* which the data should be synced. Please note that this end time is not
* guaranteed, but is more of a guideline for FirebaseJobDispatcher to go off of.
*/
.setTrigger(Trigger.executionWindow(
SYNC_INTERVAL_SECONDS,
SYNC_INTERVAL_SECONDS + SYNC_FLEXTIME_SECONDS))
/*
* If a Job with the tag with provided already exists, this new job will replace
* the old one.
*/
.setReplaceCurrent(true)
/* Once the Job is ready, call the builder's build method to return the Job */
.build();
/* Schedule the Job with the dispatcher */
dispatcher.schedule(syncSunshineJob);
}
示例30
/**
* Schedules a repeating sync of Sunshine's weather data using FirebaseJobDispatcher.
* @param context Context used to create the GooglePlayDriver that powers the
* FirebaseJobDispatcher
*/
static void scheduleFirebaseJobDispatcherSync(@NonNull final Context context) {
Driver driver = new GooglePlayDriver(context);
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(driver);
/* Create the Job to periodically sync Sunshine */
Job syncSunshineJob = dispatcher.newJobBuilder()
/* The Service that will be used to sync Sunshine's data */
.setService(SunshineFirebaseJobService.class)
/* Set the UNIQUE tag used to identify this Job */
.setTag(SUNSHINE_SYNC_TAG)
/*
* Network constraints on which this Job should run. We choose to run on any
* network, but you can also choose to run only on un-metered networks or when the
* device is charging. It might be a good idea to include a preference for this,
* as some users may not want to download any data on their mobile plan. ($$$)
*/
.setConstraints(Constraint.ON_ANY_NETWORK)
/*
* setLifetime sets how long this job should persist. The options are to keep the
* Job "forever" or to have it die the next time the device boots up.
*/
.setLifetime(Lifetime.FOREVER)
/*
* We want Sunshine's weather data to stay up to date, so we tell this Job to recur.
*/
.setRecurring(true)
/*
* We want the weather data to be synced every 3 to 4 hours. The first argument for
* Trigger's static executionWindow method is the start of the time frame when the
* sync should be performed. The second argument is the latest point in time at
* which the data should be synced. Please note that this end time is not
* guaranteed, but is more of a guideline for FirebaseJobDispatcher to go off of.
*/
.setTrigger(Trigger.executionWindow(
SYNC_INTERVAL_SECONDS,
SYNC_INTERVAL_SECONDS + SYNC_FLEXTIME_SECONDS))
/*
* If a Job with the tag with provided already exists, this new job will replace
* the old one.
*/
.setReplaceCurrent(true)
/* Once the Job is ready, call the builder's build method to return the Job */
.build();
/* Schedule the Job with the dispatcher */
dispatcher.schedule(syncSunshineJob);
}