I used FirebaseJobDispatcherin my project. This is sample code.
public class MyCustomDispatcher extends JobService {
@Override
public boolean onStartJob(JobParameters job) {
Log.e("MyCustomDispatcher", "onStartJob() called with: " + "job = [" + job.getTag() + "]");
return false;
}
@Override
public boolean onStopJob(JobParameters job) {
Log.e("MyCustomDispatcher", "onStopJob() called with: " + "job = [" + job + "]");
return false;
}
}
And to start my work, I did a simple thing in my work.
FirebaseJobDispatcher firebaseJobDispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
Job myJob = firebaseJobDispatcher.newJobBuilder()
.setService(MyCustomDispatcher.class)
.setTag("service")
.setRecurring(false)
.setTrigger(Trigger.executionWindow(0,10))
.setConstraints(Constraint.ON_ANY_NETWORK)
.build();
firebaseJobDispatcher.mustSchedule(myJob);
It starts my service and onStartJob()is called whenever I plan my work.
The only problem that I use firebaseJobDispatcher.cancel("service");, it does not cause onStopJob().
Is this actual behavior or is there something I am missing?
source
share