Firebase Jobdispatcher: Jobs that run endlessly due to an error are never scheduled again

1k views Asked by At

What happens to a recurring job that is not finished due to a crash or Android process cleaning? In my opinion, it is not possible to reschedule it. It will never be executed again.

Example

public class MyJobService extends JobService {


    @Override
    public boolean onStartJob(JobParameters job) {
    
        doSomeWork(job);

        return true; // true = there is still work going on!
    }

    private void doSomeWork(final JobParameters job) {

        new Thread() {

            public void run() {
            
                // do some work, maybe load data from internet
                // loading...
                // loading...
                // app crashes or its process is killed by Android
                
                // this piece of code is never reached!
                jobFinished(job, false);
            
            }
        }.start();
    
    }
    
}

As you can see in the code, the job can never be terminated by the crash. It will not be rescheduled afterwards.

If you want to reschedule it with FirebaseJobDispatcher.mustSchedule(), this appears in logcat:

E/FJD. ExternalReceiver: Received execution request for already running job

W/FJD. JobService: Job with tag = ... was already running

even if you run FirebaseJobDispatcher.cancel() before.

Any suggestions?

1

There are 1 answers

6
Ashik sunny On

put your code in try catch block. in catch block call jobFinished(job, true); . "true" means the job will be rescheduled.

" What happens if Android shuts down the app, e. g. in case of lack of memory?" .In this case os will raise the OutOfMemmory error and your try catch block will handle it.