4

I have used FirebaseJobDispatcher in my project. This is the 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 job i have done simple thing in my activity.

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 is starting my service and onStartJob() is being called whenever i schedule my job.

Only problem is when i use firebaseJobDispatcher.cancel("service");, it is not calling onStopJob().

Is it the actual behavior or is there anything that i am missing?

Ravi
  • 34,851
  • 21
  • 122
  • 183

2 Answers2

0

I believe onStopJob() is only called when your job is stopped before it has completed whatever onStartJob() is trying to do.

MrBovineJoni
  • 296
  • 1
  • 3
  • 15
0

I also faced this issue but when I set return true for both methods, onStopJob is getting called. I hope it will help you.

immodi
  • 607
  • 1
  • 6
  • 21