JobDispatcher.cancel () does not call onStopJob ()

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?

+4
source share
2 answers

I believe that onStopJob () is called only when your task is stopped before it completes what onStartJob () is trying to do.

0

, return true , onStopJob. , .

0

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


All Articles