Background info
So I have created an app that is mainly controlled by a notification that's supported by a service. This notification disapears when a user loses connection to a specific WiFi network, and has to appear when the user get's back home and connects to the Wifi network. Before Android O I just let the service run in the background. The service was bound to a broadcastreceiver that would tell the service whenever WiFi was connected and disconnected. The service would then act upon those changes.
The breaking change
Now we have Android Oreo with the background limitations. Because of this, and to preserve some battery, I have changed the app to stop the service whenever WiFi is disconnected, and start a Firebase Jobdispatcher job. This job will be executed whenever Android feels like it. So it may very well be that the user is connected to WiFi, and 15 minutes later the job gets executed.
The problem
I want the job to get executed immediately when the phone gets connected to a WiFi network, without having an service running. I know its possible, because I recently saw this exact same behavior in the Google Translate Android app. When you enable a language for offline translation, it only get's downloaded when WiFi is connected. Even when I close all of its services (in Developer options), it reacts immediately when I connect to WiFi.
Any ideas?
For anyone interested, here's my job config:
Job myJob = mDispatcher.newJobBuilder()
.setService(ScheduledJobService.class)
.setTag(JOB_TAG)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(1, 10))
.setLifetime(Lifetime.UNTIL_NEXT_BOOT)
.setReplaceCurrent(true)
.setConstraints(Constraint.ON_UNMETERED_NETWORK)
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
.build();
mDispatcher.mustSchedule(myJob);