FirebaseJobDispatcher fires when a network changes

I'm a little unsure of how FirebaseJobDispatcher(JobScheduler) works . What I want when a user loses an Internet connection, then reconnects to my application to start and synchronizes to check for content updates after reconnecting.

I know that we should not use the broadcast listener to connect and use the JobScheduler, but it seems that the JobScheduler is a more intelligent AlarmManager, where it will work even if there are no changes in connectivity (which I do not need).

Is this so, or I don’t understand how it works? If not, is there something that will only work when the user restores the Internet connection?

+6
source share
3 answers

JobScheduler is a great option when you want to initiate some actions that occur only when certain preconditions are fulfilled (connectivity, batteries and system broadcasts). In your case, plan some work that happens only when the user has an Internet connection.

JobScheduler API 21, Google Play . FirebaseJobDispatcher API 9 .
AndroidJob - API 14 Play Service.

FirebaseJobDispatcher Evernote - .

+3

Wi-Fi

Job myJob = mDispatcher.newJobBuilder()
                .setService(MyJobService.class)
                .setTag(JOB_TAG)
                .setRecurring(true)
                .setTrigger(Trigger.executionWindow(5, 5))
                .setLifetime(Lifetime.FOREVER)
                .setConstraints(Constraint.ON_ANY_NETWORK)
                .setReplaceCurrent(false)
                .setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
                .build();

        mDispatcher.schedule(myJob);

.setConstraints(Constraint.ON_UNMETERED_NETWORK), .

,

+1

TestApp for JobDispatcher provides some good examples; While normal, you can use Builder to create a task for the dispatcher. just found here explaining this in more detail.

/* a recurring job, being triggered in the time-frame in between 59-61 seconds */
Job.Builder builder = dispatcher
    .newJobBuilder()
    .setTag("SomeJob")
    .setService(SomeJobService.class)
    .setRecurring(true)
    .setTrigger(Trigger.executionWindow(59, 61));
0
source

Source: https://habr.com/ru/post/1016606/


All Articles